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

Query for array of usernames in Parse

Im working on this project where i try to query for users, that i have stored in an array of usernames. Is seams to work fine, but my problem is that Im ONLY retrieving user information for the LAST user in my array.

First of i have an NSMutabelArray:

 @property (nonatomic, strong) NSMutableArray *friends;

To get the usernames in to my array, i use the following code:

PFUser *user = [PFUser currentUser];
PFQuery *query = [PFQuery queryWithClassName:user.username];
[query findObjectsInBackgroundWithBlock:^(NSArray *senderId, NSError *error) {
    if (!error) {
        for (PFObject *object in senderId) {

            self.friends = [object objectForKey:@"senderId"];

            NSLog(@"%@", self.friends);

My output log displays a nice little array of 3 usernames

2014-04-02 23:05:13.834 Ribbit[10129:a0b] Current user: Molly
2014-04-02 23:05:16.007 Ribbit[10129:a0b] Molly
2014-04-02 23:05:16.008 Ribbit[10129:a0b] Billie
2014-04-02 23:05:16.008 Ribbit[10129:a0b] Ribbit

And finally, to get my users, where i only get 1, the last user, i use this code:

 PFQuery *download = [PFUser query];
[download whereKey:@"username" equalTo:self.friends];
[download findObjectsInBackgroundWithBlock:^(NSArray *results, NSError *error) {
    if (!error) {

        NSLog(@"%@", results);

So the last code snippet is where i run in to my problem, but don´t hesitate, Im open for an allover criticism on code as well. Does anyone know how to solve this problem? Or maybe help me understand where in my code Im doing something funky.

There is definitely something wrong with my array. I have tried using containedIn; but that does not work. I have also tried "manually" Query for users, @"Molly, Billie ..." and that worked fine. So i really think that the problem is that my query does not understand that my self.friend is an Array of more than one object....

I really would love some help on this one because its driving me crazy.........

Cheers!!!