Swift issue with nil found while unwrapping an Optional value NSDefautlts

前端 未结 3 879
盖世英雄少女心
盖世英雄少女心 2020-12-22 09:23

Issue with fatal error: unexpectedly found nil while unwrapping an Optional value.

let lastupdate = defaults.stringForKey(\"localdate\")
self.lastUpdate.tex         


        
3条回答
  •  渐次进展
    2020-12-22 10:06

    Try this,

    if let lastupdate = userDefaults.stringForKey("localdate"){
        self.lastUpdate.text = "Updated at " + lastupdate
        } else {
            println("nil value")
            // do what ever u want
        }
    

提交回复
热议问题