1

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

Alex May
  • 11
  • 1
  • 3
  • what is the reply/error you are getting? – harryhorn Jun 17 '15 at 05:37
  • There is no error and the delete log is called. The records are then queried and loaded into a tableview and there are the same amount of records – Alex May Jun 18 '15 at 17:10
  • I agree with Trevor's response below. It seems the records ARE deleted correctly in CloudKit based on the fact you are getting a success response – harryhorn Jun 20 '15 at 10:04

1 Answers1

0

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.

Trevor Squires
  • 531
  • 4
  • 7