Below is my function in which I have highlighted the code that works (i.e. asynchronous), but what I want is the synchronous code with PFQuery.countObjects(error: NSErrorPointer)
to work.
//Count how many violations User has.
func checkViolationStatus(usr: PFUser) -> Int32 {
var violations: Int32 = 0
var query = PFQuery(className: PF_BLOCKEDUSERS_CLASS_NAME)
query.includeKey(PF_BLOCKEDUSERS_USER)
query.whereKey(PF_BLOCKEDUSERS_USER, equalTo: usr)
//THIS WORKS BUT IS ASYNCHRONOUS AND I WANT IT TO BE SYNCHRONOUS
// query.countObjectsInBackgroundWithBlock {
// (count: Int32, error: NSError?) -> Void in
// if error == nil {
// print("Sean has played \(count) games")
// violations = count
// }
// }
//WANT TO MAKE IT SYNCHRONOUS -- THIS DOES NOT WORK
violations = query.countObjects(<#T##error: NSErrorPointer##NSErrorPointer#>)
return violations
}
How to use query.countObjects(...)
correctly here?