0
我正在使用解析來嘗試創建一個instagram風格的應用程序,用戶可以關注其他用戶。下面的代碼嘗試查詢我的分析數據庫,並檢查登錄的用戶'是否'追隨'另一個用戶。它目前進入你可以看到的地方「輸入這裏但不是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)