Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Ribbit - Querying Parse for Users and Storing Them In a NSArray

Quick question that I don't really understand.

 PFQuery *query = [PFUser query];
    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {
            self.allUsers = objects;
            [self.tableView reloadData];
        }
    }];

Why is self.allUsers set to objects? What is objects?

Why isn't it set to the query variable?

1 Answer

objects is what the query returns. so the query runs its findObjectsinBackground method, and that method returns objects. The objects variable is an array that contains whatever your query found.

if you tried setting self.allUsers to the query variable, it would not work since your query variable is of type PFQuery, and your allUsers is of type NSArray.

Cool. Thanks for explaining that!