Just started building an iOS application using Parse. I meticulously followed the Getting Started Guide and as expected, can create and save Parse objects as well as login Users. Unfortunately, when I create a PFQuery Object and try to retrieve data from parse, the query method itself executes without an error, but returns no data and in my case ignores the for-in statement in the code block. I find this particularly odd because I literally copy pasted this code from the Parse documentation.
Could someone kindly explain to me why this isn't working/provide me with a better solution? Would be eternally grateful!!
Here's my code:
(void)viewDidLoad {
[super viewDidLoad];
PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSLog(@"Test 1 retrieved %d Users.", objects.count);
for (PFObject *object in objects) {
NSLog(@"Test 2 Retrived %d Users.", objects.count);
[self.array addObject: object];
}
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
NSLog(@"%@", self.array);
}
Here's the result of the NSLog's:
2016-01-25 10:11:56.708 FSJ[4507:405721] (null)
2016-01-25 10:11:56.790 FSJ[4507:405721] Test 1 retrieved 0 Users.
Note: 1) From what I've read people seem to think this may have something to do with threading, but I tried using the findObject Method as well, which though not recommended uses the main thread, and received the same result. 2) Also, thought it might have to do with access permissions, but I made sure that in my data browser all my Read, Write, and Add permissions are checked off and are public.
findObjectsInBackgroundWithBlock:is async, that's normal log "(null)" before "Test 1" log. The issue is on the fact that you have "0" users retrieved. It's just a clarification since that doesn't seems clear for you.userQuery = PFuser.query(), in case Parse decides to make any changes to their classes, you will be unaffected using this method, where as if you query the user class the way you currently are doing it, you will have to re-write your code