swift - fatal error : unexpectedly found nil while unwrapping an Optional value - Duc Tran

标签 swift error-handling social

我注册了duc tran的SYA 2,并在newsfeed应用程序中收到此错误:

fatal error: unexpectedly found nil while unwrapping an Optional value

enter image description here

尝试访问评论时会发生这种情况。有任何想法吗?

最佳答案

这里的注释不是可选值,因此我们应该检查并设置数据。
用替换comments = media.comments

if let comments = media.comments {
            self.comments = comments
}

or



如下进行可选注释,
let comments: [Comment]? = [Comment]()

同样,在您的情况下,comments类的Media属性也应该是可选的。当您从非可选属性读取数据时,该属性不应为nil。

关于swift - fatal error : unexpectedly found nil while unwrapping an Optional value - Duc Tran,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40815509/

相关文章:

ios - 执行 webView.loadRequest(request) 时出现 "unexpectedly found nil ..."错误

ios - 如何运行命令

node.js - 如何处理 node.js 中的所有异常

iphone - 是否有适用于 ‘With Friends’ 游戏的 iOS API?

ios - interstitialWillDismissScreen 只被调用一次

ios - 应用程序委托(delegate)未被调用,project.pbxproj 已损坏

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

python - 如何在Django和Django Rest框架中覆盖/自定义所有服务器错误

iOS Core Data 与其他用户交换对象

ios - Reddit分享按钮 swift 3