0
votes

I am using Parse. In the special Parse User class (PFUser) I added a property of type "array" to each user. Now, I want to be able to retrieve/update this array. The array is called "friendsList".

I am using the Xcode/iOS Parse SDK.

EDIT: I have tried a few different parse queries but they're not working. I'm guessing it has to do with the fact that when you're querying the special class name "User" you can't use a typical query like

[PFQuery queryWithClassName:@"User"]; // This is wrong.

What I am trying to accomplish is this: currentUser tries to Add A Friend by Username. They type in the username, press Go, and I search the special User class with this code:

PFQuery *friendQuery = [PFUser query];
[friendQuery whereKey:@"username" equalTo:userNameToAdd];
[friendQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) 
{ 
    /* This is where I want to now push 'userNameToAdd' onto the friendsList Array inside the currentUser, but I can't figure out how to retrieve/update that Array called friendsList */ 

}
1

1 Answers

0
votes

Here is the original code, with the correct answer inside the { callback code block }. See the comments in there. By the way, this only adds the actual "username" of the PFUser to the friendsList Array. If you want to you can modify the code to save the actual PFUser in the array.

PFQuery *friendQuery = [PFUser query];
[friendQuery whereKey:@"username" equalTo:userNameToAdd];
[friendQuery getFirstObjectInBackgroundWithBlock:^(PFObject *object, NSError *error) 
{ 
    /* This is how you add 'userNameToAdd' to the Array called friendsList that
     * belongs to the special parse class called User (PFUser type): */

    // This is your current user
    PFUser *currentUser = [PFUser currentUser];

    // Adds object to friendList array
    [currentUser addObject:userNameToAdd forKey:@"friendsList"];

    // Saves the changes on the Parse server. This is necessary to update the actual Parse server. If you don't "save" then the changes will be lost
    [[PFUser currentUser] saveInBackground]; 

}