Issue with fatal error: unexpectedly found nil while unwrapping an Optional value.
let lastupdate = defaults.stringForKey(\"localdate\")
self.lastUpdate.tex
stringForKey returns an optional, so you can use the nil coalescing operator "??" to return an empty string "" in case of nil:
let lastupdate = defaults.stringForKey("localdate") ?? ""
let lastupdate = defaults.stringForKey("localdate")
self.lastUpdate.text = {
if let date = lastupdate {
return "Updated at \(date)"
}
return "Not yet updated"
}()
Try this,
if let lastupdate = userDefaults.stringForKey("localdate"){
self.lastUpdate.text = "Updated at " + lastupdate
} else {
println("nil value")
// do what ever u want
}