ios - 字典在展开可选值时意外发现 nil

标签 ios swift fatal-error

我正在使用 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/

相关文章:

ios - 在 Swift 中枚举 View 的 NSLayoutConstraints?

ios - 录制 iPad 2 的屏幕

ios - 在第二个动画之前查看跳跃

PHP fatal error : Allowed memory size of 268435456 bytes exhausted

Android : A/libc: Fatal signal 11 (SIGSEGV), 代码 1,tid 18372 中的故障地址 0x8

ios - fatal error : unexpectedly found nil while unwrapping an Optional value while editing textfield in swift

ios - UIWebView 在后台更新我有一个 EXC_BAD_ACCESS

ios - swift : How to get value from completionHandler

Swift: "failable initializer ' init( )' cannot override a non-failable initializer"对比默认参数

ios - 获取和设置变量有什么意义?