Deleting multiple CKRecords at the same time

394 Views Asked by At

I have been programming in objective-C for about a year now, but i am new to cloud kit. I can do simple things such as fetch, save and delete Records but I have not been able to find a way of deleting multiple Records at a time. I tried a for loop but, although there were no errors, nothing was deleted. heres some of the code:

      for (CKRecord* r in self.allRecords) {
        [[[CKContainer defaultContainer] publicCloudDatabase] deleteRecordWithID:r.recordID completionHandler:^(CKRecordID *recordID, NSError *error) {
            if (error) {
                NSLog(@"error");
            }else
                NSLog(@"deleted");
        }];
    }

allRecords is an array containing the records which i need deleting but it does not delete any of the records. Thanks

1

There are 1 best solutions below

0
On

If you need to modify (that is, save or delete) multiple records in one CloudKit round-trip, you need to use a CKModifyRecordsOperation: https://developer.apple.com/library/prerelease/ios/documentation/CloudKit/Reference/CKModifyRecordsOperation_class/index.html

You mention "allRecords is an array containing the records which i need deleting but it does not delete any of the records".

It's not clear whether you mean that the records aren't being deleted from CloudKit, or you mean that the records aren't being deleted from your self.allRecords array.

In case you're expecting the records to be removed from self.allRecords: they won't. That's your job to manage after examining the response from either the CKModifyRecordsOperation or the deleteRecordWithID:completionHandler: call in your snippet above.