Questions tagged [optional-values]

79 questions
1
vote
1 answer

Converting from one nullable type to another nullable type

How can one convert from a nullable instance of class A to nullable instance of class B, while B is subclass of A, I tried this but it crashes: class A { } class B:A { } A? instance_1=something_maybe_null; if (instance_1.GetType() ==…
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
1
vote
2 answers

iOS and Swift: Ok to force unwrap tableView.indexPath?

I have a segue from a table view controller to another view controller. Inside the method prepare(for: sender) I need to get the indexPath of the cell that triggered the segue. Is it Ok to force unwrap the index path in this case? After all the…
ehmjaysee
  • 157
  • 10
1
vote
1 answer

Swift: array check for object at index

I have an data model object with several properties. I have a dynamic array that will sometimes have some but not all of the object properties inside of it. How do I safely check if the array as anything at it's index DataModel class Order{ var…
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
1
vote
4 answers

Swift 2.0 fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

let imgURL:NSURL = NSURL(string: "\(ImageName)")! at the above line,i'm getting fatal error fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) Code : let ImageName = obj["image"] as! String let imgURL:NSURL =…
Sridhar G.K
  • 113
  • 1
  • 3
  • 14
1
vote
6 answers

Why is Optional("Text") - Swift

I just started with Swift. So I created a simple application with a label, button and a text field. When you click the button, the app has to change the label with the text of the text field. class ViewController: UIViewController { @IBOutlet…
DaniSDE
  • 111
  • 1
  • 1
  • 10
1
vote
3 answers

Ignore an optional prefix in expression

How can I get a string after a prefix that is optional? Example: Expression Result ------------------------ [asdf]xxx => xxx [foo]bar => bar []bla => bla test => test [...] is the optional part. Obviously, I need a look-around…
robsch
  • 9,358
  • 9
  • 63
  • 104
1
vote
3 answers

Concatenating an array to another optional values array with the “+=” operator

I have an array of object : var fooArray = [Foo]() If I want to append another array with Foo object i can use the += : fooArray += anotherFooArray This one works. But if i'm making the Foo objects in the array optional : var fooArray =…
Sylver
  • 2,285
  • 3
  • 29
  • 40
1
vote
1 answer

Swift - unexpectedly found nil while unwrapping an Optional value - calling variable from delegate

I'm trying to create my first iOS app I got this error "unexpectedly found nil while unwrapping an Optional value" when I try to access variable from my delegate view controller I'm trying to get a pressed cell value to be set as label text on my…
StereoNight
  • 31
  • 1
  • 4
1
vote
4 answers

Found nil while unwrapping an Optional value (Music Library)

var songList = NSMutableArray() var player = AVPlayer() var isSelected = false override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. var songs = MPMediaQuery() //…
Abdou23
  • 363
  • 1
  • 4
  • 11
1
vote
2 answers

Swift Optional Type Syntax

According to Apple's Swift guide, when you have the following Array and the following function to search through an Array: let namesArray = ["John", "Lisa", "Bill", "Jennifer"] // Note this function is set-up to return an OPTIONAL Int: func…
sirab333
  • 3,662
  • 8
  • 41
  • 54
1
vote
1 answer

Why does this work (not using vs. using optionals)?

Why does alternative1 below work flawlessly? The macros are bogus of course and for illustration purposes only: func commonPrefixLength
JanX2
  • 1,303
  • 1
  • 12
  • 19
1
vote
1 answer

HSQLDB optional IN parameter or default parameter value of stored procedure

how can I set default value for an IN parameter of a stored procedure or how can I set an IN parameter to optional in a stored procedure in HSQLDB? I have already tried all of the solution what I learned in SQL generally and I have already red…
1
vote
0 answers

How Do You Cause An Optional Element To Be Absent In C# Code Generated With Svcutil.exe's Default Serializer?

I have a WSDL from a web service server which includes the following in its types: This is supposed to represent an optional int element named countryID. When I run svcutil.exe (from…
ALEXintlsos
  • 1,809
  • 4
  • 17
  • 17
0
votes
1 answer

How do I enable google sheets value bubbles when highlighting portions of formulas

When I would create a formulas like =IF(A2=B2,"yes","no") and I highlighted the A2, it would create a little comment bubble above the highlighted text that gave the value that was in A2. And if I selected A2=B2 it would give me a comment bubble…
0
votes
0 answers

Paginated Report Matrix Fill Value if Blank from another column

I have the below matrix in the paginated report, if a cell is blank I want to fill the value from the column "All". Any idea? Image From the above example for the first row, all blank cells should be filled with a value from "All" column (49).