【问题标题】:Dictionary Unexpectedly found nil while unwrapping an Optional value解开可选值时意外发现 nil
【发布时间】:2015-06-11 20:00:30
【问题描述】:

我在展开值时使用 let 来防止意外的 nil,但我的函数仍然会导致致命错误。

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 ""
}

【问题讨论】:

  • 嗨,我认为这已经解决了问题!

标签: ios swift fatal-error


【解决方案1】:

像这样修改你的代码:

if let dictionary1 = dictionary {
    if let domain = dictionary1["domain"] as? String {
        return domain
    }
}

【讨论】:

    猜你喜欢
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 2017-04-09
    • 2018-09-22
    • 2016-06-26
    • 2016-03-12
    相关资源
    最近更新 更多