FAQ Database Discussion Community


Unwrapping Optional Type Any from Dictionary

ios,xcode,swift,dictionary,forced-unwrapping
I have previously asked a question similar to this however the answer doesn't seem to work. I have a dictionary called Settings: var settings = String: Any This is filled by reading a text file - All works fine when i run println(settings) it returns the filled dictionary as it...

Scala: Access optional value in optional object

scala,error-handling,optional,forced-unwrapping,unwrap
Is there a good way to access a Option Value inside a Option Object? The nested match cases result in a ugly tree structure. So if I have for example: case class MyObject(value: Option[Int]) val optionObject : Option[MyObject] = Some(MyObject(Some(2)) The only way I know to access the value would...

Swift - Compiler warns i haven't unwrapped an optional but then forces me to unwrap using ! rather than?

swift,xcode6,compiler-warnings,optional-values,forced-unwrapping
I've got an error in my code where the compiler gives a warning to unwrap an optional with the message Value of optional type 'NSDate?' not unwrapped; did you mean to use '!' or '?'? My code is let formatter = NSDateFormatter() let dob = currUser.valueForKey(userTextFieldKeyNames[i]) as? NSDate let dobText...

Difference between optional and forced unwrapping

swift,optional,forced-unwrapping
Below is the code for optional string for variable name yourname and yourname2. Practically what is difference between them and how forced unwrapping in case of yourname2 var yourname:String? yourname = "Paula" if yourname != nil { println("Your name is \(yourname)") } var yourname2:String! yourname2 = "John" if yourname2 !=...

unwrapping SKPhysicsBody doesn't work

sprite-kit,skphysicsbody,forced-unwrapping
In my project, I create new nodes using a class called RocketMaker. Inside this class, I have a function called applyRecurringForce()... func applyRecurringForce() { var thrust: CGVector = CGVectorMake(100, 100) physicsBody!.applyForce(thrust) } My problem is I cannot access this function from the main scene. override func update(currentTime: NSTimeInterval) { /*...