Advertise here

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Removing PFObject from NSMutableArray based on PFQuery

lukeirvinlukeirvin Posts: 388Registered Users @ @
Here's a breakdown of my Parse setup:

- User Table
- Table A (all users will get data from this table)
- Table B - Has a pointer to User
- Table C - Has a pointer to User

Users can add objects from Table A into Table B or Table C.

If a user adds something from Table A to Table B, I want that object to be removed from the array until the user removes it from Table B, then it would appear again.

Another way to look at it for context:

Table A has:

- objectID: abc
- title: Hello World

- objectID: def
- title: This is awesome!

User adds first object to Table B:

- objectID: xyz (the objectID updates when added to new table)
- title: Hello World

Now in the View Controller displaying all of Table A, I want object with title Hello World to be hidden or removed from the array for that user.

All users will be viewing Table A so I don't want anything deleted as that would remove it from all users being able to see it.

Here's my code:
- (void)refreshData {
    PFQuery *queryOne = [PFQuery queryWithClassName:@"TableA"];
    [queryOne orderByDescending:@"createdAt"];
    [queryOne setCachePolicy:kPFCachePolicyNetworkOnly];
    [queryOne findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
        if (!error) {
            self.myArray = [NSMutableArray arrayWithArray:objects];

    PFQuery *queryTwo = [PFQuery queryWithClassName:@"TableA"];

    PFQuery *queryThree = [PFQuery queryWithClassName:@"TableB"];
    PFUser *user = [PFUser currentUser];
    [queryThree whereKey:@"user" equalTo:user];
    user.ACL = [PFACL ACLWithUser:user];
    [queryThree findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {

        for (PFObject *object in objects) {
            self.myTitle = [object objectForKey:@"title"];
            [queryTwo whereKey:@"title" equalTo:self.myTitle];

        [queryTwo findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
            for (PFObject *objectToRemove in objects) {
                [self.myArray removeObject:objectToRemove];

    [self.myTableView reloadData];
Sign In or Register to comment.