我有一个扩展PFQueryTableViewController的类。在此类的 queryForTable() 实现中,我试图获取一些数据以添加以使用findObjectsInBackgroundWithBlock
. 问题是,由于findObjectsInBackgroundWithBlock
是异步的,我如何使用从 中获取的数据findObjectsInBackgroundWithBlock
并使用它在下面构建query
并执行return query
.
我的代码和错误如下所示。
override func queryForTable() -> PFQuery {
let query = PFUser.query()
//let query = PFQuery(className: "Room")
query?.whereKey("objectId", notEqualTo: PFUser.currentUser()!.objectId!)
//Showing OnlineUsers only
let onlineUsersQuery = PFQuery(className: "OnlineUsers")
onlineUsersQuery.whereKey("user", equalTo: PFUser.currentUser()!)
onlineUsersQuery.findObjectsInBackgroundWithBlock({ (results:[AnyObject]?, error:NSError?) -> Void in
let usersOnlineNow = results as! [PFObject]
for user in usersOnlineNow {
self.mLog.printToLog("Select only users who are in the OnLineUsers column")
query?.whereKey("objectId", equalTo: PFUser.currentUser()!.objectId!)
//query?.whereKey("objectId", equalTo: "noone")
if self.searchInProgress {
query!.whereKey("username", containsString: self.searchString)
}
if self.objects!.count == 0 {
//https://groups.google.com/forum/#!topic/parse-developers/7O9YCHNbuEo
query!.cachePolicy = PFCachePolicy.CacheThenNetwork //kPFCachePolicyCacheThenNetwork
//query.cachePolicy = kPFCachePolicyCacheThenNetwork
}
query!.orderByAscending("username")
return query!
}
})
// query!.orderByAscending("username")
//
// return query!
}