Can someone show me an example with the correct syntax (swift please) to do a synchronous query with try/catch block. Thanks
Asked
Active
Viewed 477 times
1 Answers
2
Here is an example using the synchronous findObjects()
on PFQuery
.
let query = PFQuery()
do {
let results: [PFObject] = try query.findObjects()
print(results)
} catch {
print(error)
}

Kevin
- 16,696
- 7
- 51
- 68
-
then I do stuff with the objects in the DO block ? like a = object.objectForKey..... – user3722523 Dec 16 '15 at 05:26
-
I updated the question to assign the results to an array – Kevin Dec 16 '15 at 05:28
-
@Kevin Is query.findObjects() not heavily depreciated in recent Parse api installations in favour of query.findObjectsInBackgroundWithBlock(), which removes the need for try/catch handling and would make handling issues easier? – Cailean Wilkinson Dec 16 '15 at 06:35
-
@Hyperion no, findObjects() is synchronous whereas findObjectsInBackgroundWithBlock() is asynchronous. See here http://stackoverflow.com/questions/21122842/whats-the-difference-between-synchronous-and-asynchronous-calls-in-objective-c – user3722523 Dec 16 '15 at 14:38