I am testing CoreData+CloudKit, i.e. I am using an NSPersistentCloudKitContainer
that handles all communication with iCloud.
When I launch the app, CoreData automatically synchronizes with iCloud, i.e. (among others) inserted or updated records are imported to CoreData. No record is ever deleted.
My tests run on the simulator.
My 1st attempt was to use only the viewContext
. To merge remote changes into this context, I set
viewContext.automaticallyMergesChangesFromParent = true
Additionally, I am using history tracking as suggested by Apple, with the exception that history processing also uses the viewContext
, not a new background context.
This worked fine, except for the expected blocking of the UI by using the viewContext
.
My 2nd attempt was thus to process the history by a background context (as suggested by Apple).
Now the following error is repeatedly logged (apparently forever):
CoreData: Delete propagation prefetching failed with exception: The fetch request's entity 0x6000017a2050 'NSCKImportOperation' appears to be from a different NSManagedObjectModel than this context's
This error is logged even after I deleted all iCloud records in the Dashboard, and deleted the app from the simulator.
I am using only a single NSManagedObjectModel
with relations, but all relations have the delete rule „No action“.
To check the reason for this error, I set a runtime breakpoint, and the app stopped with the following stack trace:
I should mention that the error disappears, if I set
viewContext.automaticallyMergesChangesFromParent = false
but I need of course automatic merging for a correct operation.
My questions are:
Is this really an error? (The logs says „it appears…“).
What could be the reason for it, and how could it be avoided?
PS: There are many other posts related to CoreData prefetching, but I did not found one that relates to CoreData+CloudKit