Reputation: 554
Is there any way to make a parse query synchronous? I tried changing the query to findObjects instead of findObjectsInBackgroundWithBlock. I can't seem to figure out the syntax of that though. Can someone help me out with this? Any help is appreciated. Thanks.
var messageQuery = PFQuery(className: "Message")
messageQuery.whereKey("GUID", equalTo: GUID)
messageQuery.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects.count) scores.")
// Do something with the found objects
if let objects = objects as? [PFObject] {
for object in objects {
println("in loop of objects retrieved")
object.delete()
}
}
messages.removeAtIndex(messageIndex)
//objectIDArr.removeAtIndex(messageIndex)
}else {
// Log details of the failure
println("Error: \(error) \(error.userInfo!)")
}
}
Upvotes: 1
Views: 2182
Reputation: 4413
You can call the findObjects
method, which returns an NSArray.
See the reference on parse
e.g.:
PFQuery query = PFQuery(classname: "Message")
query.whereKey("GUID", equalTo: GUID)
NSArray messages = query.findObjects()
for message in messages {
//do whatever you want with your message object
}
Upvotes: 3