我需要查询类中的所有对象,并按Swift中每个对象的频率对它们进行排序。我正在使用...
获取查询// Define the query that will provide the data for the table view
override func queryForTable() -> PFQuery{
var query = PFQuery(className: "Upvotes")
return query
}
...但似乎无法检索objects.count项目,因为我无法使用带有findObjectsInBackground
调用的异步完成块。这是我应该在cellForRowAtIndexPath()
?
答案 0 :(得分:0)
但你可以这样做:
class demo: UIViewController {
var parseObjects: NSArray!
override func viewDidLoad() {
}
// Define the query that will provide the data for the table view
func yourQuery() -> PFQuery {
var query = PFQuery(className: "Upvotes")
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if (objects!.count > 0) {
parseObjects = objects //Store those objects in your variable
}
} else {
// Log details of the failure
println("Error: \(error) \(error!.userInfo!)")
}
}
}
}
之后在tableViewDelegate中使用parseObjects变量...