Delete all CloudKit entries every day from a particular record type

Therefore, I want to erase every record for a certain type of record every day. So basically, I want the data to be wiped out at 12:00 so that it is fresh the next day. How can I do it? Is this something I could configure in the CloudKit panel, or would I need to install it programmatically?

+7
ios swift cloudkit
source share
3 answers

Removing entries from the control panel is a lot of work if you need to delete multiple entries.

The best workaround is to create a separate record type that will contain one record for each day. Then, in the entries you want to delete on that day, set the CKReference for that particular day entry and set its action to CKReferenceAction.DeleteSelf

After that, you will only need to delete the daily entry, and all related entries will be deleted. Deleting one entry can easily be done from the toolbar, or you could create functionality in your application, or you could create a second application for administrative actions.

+9
source share

Try something like this:

let publicDb = CKContainer.defaultContainer().publicCloudDatabase let query = CKQuery(recordType: "RECORD TYPE", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil)) publicDb.performQuery(query, inZoneWithID: nil) { (records, error) in if error == nil { for record in records! { publicDb.deleteRecordWithID(record.recordID, completionHandler: { (recordId, error) in if error == nil { //Record deleted } }) } } } 

"RECORD TYPE" should be your record type. Hope this helps.

+5
source share
 func deleteAllRecords() { let publicDatabase: CKDatabase = CKContainer.defaultContainer().publicCloudDatabase // fetch records from iCloud, get their recordID and then delete them var recordIDsArray: [CKRecordID] = [] let operation = CKModifyRecordsOperation(recordsToSave: nil, recordIDsToDelete: recordIDsArray) operation.modifyRecordsCompletionBlock = { (savedRecords: [CKRecord]?, deletedRecordIDs: [CKRecordID]?, error: NSError?) in print("deleted all records") } publicDatabase.addOperation(operation) } 
+4
source share

All Articles