Search code examples
iosobjective-cparse-platformpfquerypfuser

Retrieve all guildmembers in the same guild as you using Parse


how do i retrieve all the guildmembers in your guild using parse?

Here is my code:

PFUser *currentuser = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:@"User"];
[query whereKey:@"connectedGuild" equalTo:currentuser[@"connectedGuild"]];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
    NSLog(@"There are %d guildmembers. Error:%@", comments.count, error);
}];

My log:

There are 0 guild members. Error:(null)

connectedGuild is a pointer to a guild class where i store all the guilds.


Solution

  • Queries of the PFUser class must be instantiated a little differently. Try this:

    PFUser *currentuser = [PFUser currentUser];
    PFQuery *query = [PFUser query];
    [query whereKey:@"connectedGuild" equalTo:currentuser[@"connectedGuild"]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
        NSLog(@"There are %d guildmembers. Error:%@", comments.count, error);
    }];
    

    For more information, see the Parse.com website here: https://www.parse.com/questions/get-pfuser-in-pfquery-using-ios-api