У меня проблемы с UserDefaults.
import Foundation
class Utility: NSObject {
func storeBaseDetail(firstname:String,lastname:String,picStr:String,email:String,usrname:String,user_Id:String) {
UserDefaults.standard.set(firstname, forKey: "firstname")
UserDefaults.standard.set(lastname, forKey: "lastname")
UserDefaults.standard.set(picStr, forKey: "picStr")
UserDefaults.standard.set(email, forKey: "email")
UserDefaults.standard.set(usrname, forKey: "usrname")
UserDefaults.standard.set(user_Id, forKey: "id")
UserDefaults.standard.synchronize()
}
func getBaseDetail()->(firstName:String,lastName:String,picStr:String,email:String,usrname:String,user_Id:String){
return ((UserDefaults.standard.value(forKey: "firstname") as! String),(UserDefaults.standard.value(forKey: "lastname") as! String),(UserDefaults.standard.value(forKey: "picStr") as? String)!,(UserDefaults.standard.value(forKey: "email") as! String),(UserDefaults.standard.value(forKey: "usrname") as! String),(UserDefaults.standard.value(forKey: "id") as! String))
}
func storeBaseDetail(firstname:String,lastname:String,picStr:String,email:String,usrname:String,user_Id:String) {
UserDefaults.standard.set(firstname, forKey: "firstname")
UserDefaults.standard.set(lastname, forKey: "lastname")
UserDefaults.standard.set(picStr, forKey: "picStr")
UserDefaults.standard.set(email, forKey: "email")
UserDefaults.standard.set(usrname, forKey: "usrname")
UserDefaults.standard.set(user_Id, forKey: "id")
UserDefaults.standard.synchronize()
}
func getBaseDetail()->(firstName:String,lastName:String,picStr:String,email:String,usrname:String,user_Id:String){
return ((UserDefaults.standard.value(forKey: "firstname") as! String),(UserDefaults.standard.value(forKey: "lastname") as! String),(UserDefaults.standard.value(forKey: "picStr") as? String)!,(UserDefaults.standard.value(forKey: "email") as! String),(UserDefaults.standard.value(forKey: "usrname") as! String),(UserDefaults.standard.value(forKey: "id") as! String))
}
}
Если я назову это UserDefaults:
if Utility().getBaseDetail().firstName != ""{
userNameLbl.text = "\(Utility().getBaseDetail().firstName) \(Utility().getBaseDetail().lastName)"
}
Я получаю эту ошибку:
Поток 1: неустранимая ошибка: неожиданно обнаружен ноль при развертывании необязательного значения