gpt4 book ai didi

ios - 为什么我会收到以下错误 : "fatal error: unexpectedly found nil while unwrapping an Optional value"? - 如何具体修复它?

转载 作者:行者123 更新时间:2023-11-30 13:59:53 25 4
gpt4 key购买 nike

这是我的代码:

var usernames = [""]
var userids = [""]
var isFollowing = ["":false]

var refresher: UIRefreshControl!

func refresh() {

var query = PFUser.query()

query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

if let users = objects {

self.usernames.removeAll(keepCapacity: true)
self.userids.removeAll(keepCapacity: true)
self.isFollowing.removeAll(keepCapacity: true)

for object in users {

if let user = object as? PFUser {

if user.objectId != PFUser.currentUser()!.objectId {

self.usernames.append(user.username!)
self.userids.append(user.objectId!)

var query = PFQuery(className: "followers")

query.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!)
query.whereKey("following", equalTo: user.objectId!)

query.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

if let objects = objects {

if objects.count > 0 {

self.isFollowing[user.objectId!] = true

} else {

self.isFollowing[user.objectId!] = false

}
}

if self.isFollowing.count == self.usernames.count {

self.tableView.reloadData()

self.refresher.endRefreshing()

}

})


}

}

}

}





})

我在这行收到 fatal error ,内容如下:

query.whereKey("follower", equalTo: PFUser.currentUser()!.objectId!) query.whereKey("following", equalTo: user.objectId!)

我该如何解决这个问题?我搜索了其他几个帖子,但找不到有用的东西。当您提供建议时,请非常具体——我相对来说是一个新手。

最佳答案

正如评论中所说,您的值(value)观之一是零。

在查询之前插入以下代码并修复返回 nil 的方法:

if (PFUser.currentUser() == nil) {
print("currentUser() is nil");
} else if (PFUser.currentUser()!.objectId == nil) {
print("PFUser.currentUser()!.objectId is nil");
} else if (user.objectId == nil) {
print("user.objectId is nil");
}

关于ios - 为什么我会收到以下错误 : "fatal error: unexpectedly found nil while unwrapping an Optional value"? - 如何具体修复它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33127050/

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