我正在使用 let 来防止在展开值时出现意外的 nil,但我的函数仍然会导致 fatal error 。
fatal error: unexpectedly found nil while unwrapping an Optional value
-
class func getDomain() -> String {
let (dictionary, error) = Locksmith.loadDataForUserAccount("account")
if let dictionary = dictionary {
if let domain = dictionary["domain"] as? String {
return domain
}
}
return ""
}
最佳答案
像这样修改你的代码:
if let dictionary1 = dictionary {
if let domain = dictionary1["domain"] as? String {
return domain
}
}
关于ios - 字典在展开可选值时意外发现 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29487926/