gpt4 book ai didi

xcode - Swift 2 + 解析 : Unexpectedly found nil while unwrapping an Optional value

转载 作者:行者123 更新时间:2023-11-30 10:08:19 26 4
gpt4 key购买 nike

我有一些代码可以查询 Parse 数据库中的类。但有时,当我登录并重定向到此 View 时,我会收到“ fatal error :展开可选值时意外发现 nil”

这是我的代码:

let getPost = PFQuery(className: "Posts")
getPost.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

if let objects = objects {

self.messages.removeAll(keepCapacity: true)
self.users.removeAll(keepCapacity: true)
self.usernames.removeAll(keepCapacity: true)

for object in objects {

self.messages.append(object["message"] as! String)

//////////THE LINE BELOW GIVES ME THE PROBLEM
self.usernames.append(self.users[object["userId"] as! String]!)

self.tableView.reloadData()
}
}
}

self.refresher.endRefreshing()

有人知道我做错了什么吗?

最佳答案

在重复循环之前,self.users 的所有项目都会被删除,因此 self.users["whatever"] 将始终失败。

PS:并将 self.tableView.reloadData() 放在重复循环之后。

关于xcode - Swift 2 + 解析 : Unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34796206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com