Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 致命错误:在展开可选值-Duc-Tran时意外发现nil_Swift_Error Handling_Social - Fatal编程技术网

Swift 致命错误:在展开可选值-Duc-Tran时意外发现nil

Swift 致命错误:在展开可选值-Duc-Tran时意外发现nil,swift,error-handling,social,Swift,Error Handling,Social,我注册了duc tran的SYA 2,在newsfeed应用程序中出现以下错误: fatal error: unexpectedly found nil while unwrapping an Optional value 它发生在尝试访问评论时。有什么想法吗?注释在这里不是可选值,因此我们应该检查并设置数据。 将comments=media.comments替换为 if let comments = media.comments { self.comments =

我注册了duc tran的SYA 2,在newsfeed应用程序中出现以下错误:

fatal error: unexpectedly found nil while unwrapping an Optional value


它发生在尝试访问评论时。有什么想法吗?

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

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

在以下可选位置发表评论:

let comments: [Comment]? = [Comment]()

在您的情况下,
Media
class上的
comments
属性也应该是可选的。当您从和非可选属性读取数据时,该属性不应为零。

强制展开时可能存在重复
var media:media,但没有为其提供初始值,也没有在访问itthanks以获取帮助之前对其进行设置,但两者都不起作用仍然存在相同的错误:/