I have a parse back end for my iOS app. I have a parse class called \"quiz\". How can I read the number of rows in the Parse class, I have to use it in my iOS app?
Since the count is retrieved asynchronously, the way to return the count is inside a completion closure instead of using return cnt.
Here is an example:
func countObjectsWithCompletion(completion: (Int?)->(Void))
{
var query = PFQuery(className:"quiz")
query.findObjectsInBackgroundWithBlock {
(objects: [PFObject]?, error: NSError?) -> Void in
if error == nil
{
// The find succeeded.
print("Successfully retrieved \(objects!.count) scores.")
completion(objects!.count)
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
completion(nil)
}
}
}
countObjectsWithCompletion { (myObjectCount: Int?) in
if let cnt = myObjectCount {
print("count is \(cnt)")
} else {
print("error getting count")
}
}