I have created CKQuerySubscriptions to monitor remote insertion, modification and deletion of CKRecords. For inserted and modified records this works well because I can query CloudKit for the affected CKRecord, get the associated NSManagedObject and then handle the insertion and modification from there.
For deleted CKRecords, this is a problem because by the time the notification has been fired, the CKRecord has already been removed from CloudKit. This means the fetch request to get the now deleted CKRecord fails, so I have no way to know which NSManagedObject was associated with the deleted CKRecord.
I don't know if I'm going about this all the wrong way and if there is an easier way to handle all of this!
This works, but it feels a bit clunky. There must be an easier way! But if not, if this code is useful to anybody else, feel free to comment if you want the code used in any of the helper methods not shown (e.g. in the
+[CoreDataFunctions fetchRecordsForEntityType: withCloudIDs: completion:]method);