Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse IOS deleting all objects wherekey = objectID

Is there an easy way to delete all objects within a particular class (i.e. messages) which satisfy a particular condition, such as "UserID" = user, so that all of the rows within my message class associated with a particular user will be deleted?

like image 747
Apollo Avatar asked Feb 13 '14 19:02

Apollo


Video Answer


1 Answers

Try this,

 PFQuery *query = [PFQuery queryWithClassName:@"messages"];
 [query whereKey:@"UserID" equalTo:@"user"];
 [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
 if (!error) {
     // The find succeeded.
     NSLog(@"Successfully retrieved %d scores.", objects.count);
     // Do something with the found objects
     for (PFObject *object in objects) {
         [object deleteInBackground];
     }
 } else {
     // Log details of the failure
     NSLog(@"Error: %@ %@", error, [error userInfo]);
 }
}];

Update

replace

for (PFObject *object in objects) {
    [object deleteInBackground];
}

with

[PFObject deleteAllInBackground:objects];

thanks mikewoz for the update.

like image 94
Akhilrajtr Avatar answered Oct 13 '22 06:10

Akhilrajtr