Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!!!