CloudKit: CKQueryOperation for deleted records

894 views Asked by At

Is there a way to query CloudKit for recently deleted items (from a particular timestamp, perhaps), without using CKFetchRecordChangesOperation? I am using a public database so I can't use custom zones (which would be a requirement for CKFetchRecordChangesOperation) ... so I need a way to simulate this with public databases.

I want to be able to efficiently update my local Core Data cache for changes in the CloudKit records. When you query for CloudKit records, the CKRecord seems to have a creationDate and modificationDate property, which one can query for to see recently created / modified records, but that won't work for records that were deleted in CloudKit.

What would be an effective strategy here?

2

There are 2 answers

1
amleszk On

One solution I have thought about is maintaining a "deletedDate" property on CKRecord,

This is not required

You want a CKFetchRecordZoneChangesOperation

Go watch the WWDC video here: https://developer.apple.com/videos/play/wwdc2014/231/

https://developer.apple.com/icloud/

1
Z S On

One solution I have thought about is maintaining a "deletedDate" property on CKRecord, so when data is 'deleted', you don't actually delete the record from CloudKit, instead just update this property. That will make it possible for other devices to query for records that have been deleted recently, so you can update the local cache. You can also periodically check for records that have deletedDate more than a 1 week or something and actually remove the records at that point (though you want to watch out for multiple devices deleting the records at the same time, and other edge cases). Not the most elegant solution, but could work. If there's a better option, would love to hear it.