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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With