I am trying to figure out why swift is returning the 0 that I declared in the beginning of the function instead of returning the number that I set it to from Parse.
func getPhotosSubmitted(quest: String) -> Int{
var num = 0
var query = PFQuery(className:"Quest")
query.whereKey("questName", equalTo:quest)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
// NSLog("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
for object in objects {
num = (object["numOfSubmittedPhotos"] as Int)
println("---\(num)")
}
} else {
// Log details of the failure
//NSLog("Error: %@ %@", error, error.userInfo!)
}
}
return num
}
This func will return 0 everytime, as if it is not waiting for: num = (object["numOfSubmittedPhotos"] as Int)
When I try to return (object["numOfSubmittedPhotos"] as Int)
it throws an error saying that Int is not convertible to void
I print a test line to see what value I get from Parse and it is the correct value that is not 0. Does anyone see a problem in this code?