All Questions
Tagged with option-type unwrap
57
questions
0
votes
1
answer
153
views
Error to use a shorter spelling to unwrap a value
in Swift documentation at https://docs.swift.org/swift-book/GuidedTour/GuidedTour.html, there are examples about usage of optionals and unwrapping them. When I try the examples on my Macbook, I got an ...
1
vote
1
answer
337
views
Why is in Rust the expression in Option.and evaluated, if option is None?
I don't understand, why Option.and() is evaluated, if option is None. The documentation says ....
Returns None if the option is None, otherwise it returns optb (the argument of and()).
So I would ...
1
vote
2
answers
2k
views
SwiftUI, Fatal error: Unexpectedly found nil while unwrapping an Optional value
func loadImageFromUrl() {
guard let urlString = self.urlString else {
return
}
let url = URL(string: urlString)!
let task = URLSession.shared.dataTask(with: url, ...
0
votes
2
answers
465
views
Unwrap optional text from JSON
I have multiple strings returned from JSON and tried various options, but couldn't unwrap the optional content in it. Code snippet below
let parsedData = try JSONSerialization.jsonObject(with: data!,...
0
votes
2
answers
1k
views
How can I safety unwrap an optional with a default value using `coalescing unwrapping` - Not workig - Swift
How can I safety unwrap the first optional item from arrayOfStrings to get just the pounds with a default value of 0 using coalescing unwrapping?
Based on the code below, what I want is to be able to ...
1
vote
1
answer
279
views
Swift: Can't unwrap an optional inside a loop
I can't understand why unwrapping an optional value is possible in this case:
let name: String? = "Toto"
guard let name = name else { fatalError() }
print(name)
but not when this snippet is wrapped ...
-1
votes
1
answer
245
views
Swift Error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
I am getting this problem in my code:
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
This message appears on this line of my code:
try player = AVAudioPlayer(...
-4
votes
1
answer
80
views
Xcode unexpectedly found nil while unwrapping an Optional, but no idea why
Xcode gives me the following error but I have no idea where this is coming from. I printed elpasedTime value and it contains the value!
But it still says it found nil when unwrapping and I have no ...
-1
votes
2
answers
126
views
I have an error when unwrapping an optional IBOutlet (Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value)
I know why this problem is happening but I don’t know how to fix it. I used an override func to add to the method becomeFirstResponder (which does exactly what it says) from the class ViewController ...
1
vote
2
answers
689
views
Haskell unwrap Maybe keep polymorphism
Haskell beginner here again. If I want to unwrap a Maybe type and want to keep it abstract I would use:
fUnwrap :: Maybe a -> a
fUnwrap (Just n) = n
fUnwrap Nothing = ???
No matter what I do ...
-1
votes
2
answers
135
views
How to unwrap programmed UIButton (swift4)
I am trying to create a button using programmed constraints. I am trying to not use the storyboard. I am having trouble unwrapping the button. How do I do this?
import UIKit
var aa: [...
2
votes
2
answers
1k
views
Ternary Unwrapping in swift
In swift i'm using this code:
var categories: Results<Category>? //Realm dataType
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let ...
2
votes
1
answer
932
views
swift cast from AnyHashable to enum
I have this playground:
import Foundation
enum WeekDay: Int {
case mon, tues, wed, thurs, fri, sat, sun
}
let wd = WeekDay(rawValue: 0)! // mon
let param = [wd: [1, 2, 3]]
message(dict: param)
...
2
votes
1
answer
605
views
Why using implicit unwrap or force unwrap letting the app crash at some stage not beneficial?
My point is at some places we know that the variable won't have nil at all but due to some reason we can't instantiate it in the class's init function so we have to make it optional.
I also know that ...
2
votes
2
answers
1k
views
Swift type casting / downcasting
Why does the Sprite Kit Game template project created by Xcode use as!:
if let sceneNode = scene.rootNode as! GameScene? {...}
Wouldn't the following be equally good?
if let sceneNode = scene....