I got the Problem if i try print a var i sometimes get a "Optional("var")" if i try log it or print it to a lable, but else when i dont get it.
See here
ViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NSUserDefaults.standardUserDefaults().setObject("notWorking", forKey: "testvar")
NSUserDefaults.standardUserDefaults().synchronize()
println(NSUserDefaults.standardUserDefaults().stringForKey("testvar"))
var test = "working"
println(test)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Anyone can explain when this "Optional" appears and what its use for? How can i remove it?
oki just need to add a "!"
println(NSUserDefaults.standardUserDefaults().stringForKey("testvar")!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With