gpt4 book ai didi

ios - 多个查询返回错误结果

转载 作者:行者123 更新时间:2023-11-30 13:51:56 26 4
gpt4 key购买 nike

我正在使用 parse 来尝试创建一个 Instagram 风格的应用程序,用户可以在其中关注其他用户。下面的代码尝试查询我的解析数据库并检查登录的用户是否“关注”另一个用户。它当前进入您可以看到“ENTERS HERE BUT DOES NOT APPEND”的位置。两个问题:1. 为所有用户输入此位置,而不仅仅是当前登录用户关注的用户2.append.isfollowing 不起作用。最初,isfollowing.count是0,当我再次在末尾打印它时,它仍然是0。即使它进入了它包含的if语句,追加也不起作用下面的代码 - 谢谢!

var usernames = [""]
var userids = [""]
var isFollowing = [Bool]()

override func viewDidLoad() {
super.viewDidLoad()


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

//check if we have any objects
if let users = objects {

//for each element in the users array
for object in users {

//convert to PFuser
if let user = object as? PFUser {

//check if the current user is following each user. if so update isfollowing array
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 objects returns something
if let objects = objects {

//if we enter here we know that the logged in user is following the curr user. Update the isfollowing array
//ENTERS HERE BUT DOES NOT APPEND
self.isFollowing.append(true)

} else {
self.isFollowing.append(false)
}
})
}
}
}
//reload the table data
self.tableView.reloadData()
})

print(self.isFollowing.count)

最佳答案

  1. It is entering this location for all users, not just the ones that the currently logged in

由内部查询测试的条件,if letobjects=objects 测试数组是否已定义(非零)。您想要的是测试数组是否非零且非空,例如:

if objects?.count > 0 {  // we found at least one
  1. the append.isfollowing is not working

附加到 isFollowing 的代码异步运行。 viewDidLoad 末尾的打印语句在查询完成之前立即运行。这就是为什么它看起来不起作用(它只是还没有起作用)。

关于ios - 多个查询返回错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34156867/

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