I have such query to parse.com. Why the numObjects variable has different values inside the findObjectsInBackgroundWithBlock and on the function exits
func searchUserInParse () -> Int {
var numObjects : Int = 0 // the num return objects from query
var query = PFQuery(className:"Bets")
query.whereKey("user", equalTo: "Bob")
query.findObjectsInBackgroundWithBlock {
(objects: AnyObject[]!, error: NSError!) -> Void in
if !error {
numObjects = objects.count
println(numObjects) // at this point the value = 1
} else {
// Log details of the failure
NSLog("Error: %@ %@", error, error.userInfo)
}
}
println(numObjects) // at this point the value = 0
return numObjects
}
println(numObjects)is called before the above code block.