Questions tagged [optional-values]

79 questions
0
votes
2 answers

Swift: Can weak reference be deallocated during optional binding?

Lets examine the following example SomeLib.someAsyncFunction { [weak someVariable] in if let someVariableU = someVariable { // now someVariableU is unwrapped and strong reference created , we can use it as regular } } I assume that…
starwarrior8809
  • 361
  • 1
  • 10
0
votes
1 answer

Cannot convert return expression of type 'User' to return type 'User?' for getting currentUser from Firebase

I'm new to Swift and I'm having trouble returning a User? value from currentUser in Firebase for CURRENT_USER. I have my User class declaration below and it's located in a separate UserApi file. All the help is greatly appreciated! var CURRENT_USER:…
0
votes
3 answers

Array declared for collectionview null value optional

I created an array that is my data for my collection view. I am attempting to tap on the CollectionViewCell and play the sound contained in the file component of my array. I dont't know how to play the sound and can't even get started because I get…
alex00x0
  • 27
  • 6
0
votes
4 answers

Unwrapping an optional in Swift 4

I have the following code in a playground: // Create an empty array of optional integers var someOptionalInts = [Int?]() // Create a function squaredSums3 with one argument, i.e. an Array of optional Ints func squaredSums3(_ someOptionalInts:…
user5487286
0
votes
2 answers

How to make a optional group, but if the group exists most match with my regex?

I have this JS regex: var re = /(\w\w\d-{1})?\w\w-{1}\w-{1}?/; For file name, and the first group must be optional: Complete name example. Example: qq8-qq-q-anything => OK Without first group: qq-q-anything => OK But if I put anything, still…
Lucas Andrade
  • 4,315
  • 5
  • 29
  • 50
0
votes
2 answers

Swift Direction Request does not calculate in if statement correctly

I wanted to calculate distances from users current location to many different location and put these calculations into calculations array. So I can sort this array and find the closest location. At the end I want to show the closest location on the…
0
votes
2 answers

Swift viewcontroller declaration returning nil

let saveNewItem = SaveNewItem() print(saveNewItem) if saveNewItem != nil { print("Contains a value!") _ = UIApplication.shared.keyWindow!.rootViewController self.present(saveNewItem, animated: true, completion:…
0
votes
4 answers

UILabel set text unexpectedly found nil while unwrapping an Optional value Swift 3

In my custom collectionview cell I have @IBOutlet weak var boardNameLabel: UILabel! var boardInfoDic: Dictionary? = [String : AnyObject]() func updateItemAtIndexPath(_ indexPath: NSIndexPath) { if let string = boardInfoDic?["description"] …
SriKanth
  • 459
  • 7
  • 27
0
votes
2 answers

Why doesn't my scrollView page load on my iOs app? Getting error: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0)

I am building an app using a codeschool tutorial, but even though I have followed the exact code and steps to build a scrollView page correctly, it only displays a blank screen on the iOS simulator. What am I doing incorrectly? Here is my…
Pigpocket
  • 449
  • 5
  • 24
0
votes
3 answers

Why is guard not protect me from nil

I make some kind of JSON parsing with a weatherAPI. To prevent me of running into nullPointer (maybe the page is offline or something) I covered my parsing into a guard, because I thought he protect me for unwrapping optional value. guard let…
kuemme01
  • 472
  • 5
  • 19
0
votes
2 answers

unexpectedly found nil while unwrapping an Optional value dispatch-async

I am trying to implement loading data from Parse server after tapping a button on postVC to load data and navigate to guestVC. It was working fine and at some point began to crash the app...not sure why? I am getting the fatal error: unexpectedly…
user3708224
  • 1,229
  • 4
  • 19
  • 37
0
votes
2 answers

Problems checking to see if a value exists in Swift 2

I'm writing a quiz app and there is a table view to add a subject (The name is saved to core data) and when you select an index path it passes the subject to a detail view controller (this works just fine on its own) but what I'm having trouble with…
Echizzle
  • 3,359
  • 5
  • 17
  • 28
0
votes
1 answer

Is it necessary to set variable 'possibleIntegerValue' to 'optional Int(Int?)' or it is ok to set 'possibleIntegerValue' to the type 'Int' instead?

I'm new to Swift and is trying to learn the concept of optional values. My question is, within the context of the code before, is necessary to set variable 'possibleIntegerValue' to 'optional Int(Int?)' or it is ok to omit the ? sign and set…
Thor
  • 9,638
  • 15
  • 62
  • 137
0
votes
2 answers

Why does Swift 2 favor forced unwrap over optionals?

I no longer see Xcode complaining that certain things need optionals (the "?"). Now it is always forced unwrapped (the bang "!"). Is there any reason to use optionals anymore when we now have forced unwrap?
4thSpace
  • 43,672
  • 97
  • 296
  • 475
0
votes
1 answer

change collection optional value in swift?

rowDescriptor is a AnyObject? type, I get convert self.rowDescriptor?.value to images. I want to add image to the self.rowDescriptor?.value. I failed to do it as below. images has one value. but self.rowDescriptor?.value still empty. I can't find…
kai
  • 310
  • 3
  • 14