iosobjective-cparse-platformpfuser

Parse following PFUser


I'm trying to make a follow action with parse on my ios9 project but i have a little problem when retreiving the PFUser from parse using objectId can anyone help me please (the problem is in adding the user ID of current user to the user followed )

- (IBAction)followButtonAction:(id)sender {

PFQuery * query = [PFUser query];
[query whereKey:@"objectId" equalTo:_a.userId];   
NSArray *objects = [query findObjects];   
PFUser *user= objects.firstObject;

//add the user ID for the cell we are following to the array of followed items in the user class in parse
    [[PFUser currentUser] addUniqueObject:_a.userId forKey:@"followed"];
    [[PFUser currentUser] saveInBackground];

//add the user ID to the user that the user followed
    [user addUniqueObject:[PFUser currentUser].objectId forKey:@"followers"];
    [user saveInBackground];
}

Solution

  • Assuming your question is about the long-running operation (as per your comment):

    Your query is being executed on the main thread, because you called [query findObjects]. Use findObjectsInBackgroundWithBlock instead, and place all the code after that inside the callback.