Hello,
I have an issue in an app which is yet unreleased.
The app uses Core Data, and I recently added CloudKit integration.
Whenever I start the app data get automatically downloaded by CloudKit and I get this log:
<NSCloudKitMirroringDelegate: 0x600001da61b0> - Never successfully initialized and cannot execute request '<NSCloudKitMirroringImportRequest: 0x6000024c88a0> D3FB21AB-94ED-40B7-859B-6CBEE6149473' due to error: Error Domain=NSCocoaErrorDomain Code=134404 "(null)" UserInfo={NSDetailedErrors=(
"Error Domain=NSCocoaErrorDomain Code=133021 \"(null)\" UserInfo={NSExceptionOmitCallstacks=true, conflictList=(\n \"NSConstraintConflict (0x600003f40e00) for constraint (\\n name\\n): database: 0x8143748c0004e8e1 <x-coredata://272191BB-7D10-41DD-8E4B-56F4ECE4AB9F/Ingredient/p195>, conflictedObjects: (\\n \\\"0x8143748c181ce8e1 <x-coredata://272191BB-7D10-41DD-8E4B-56F4ECE4AB9F/Ingredient/p1733>\\\"\\n)\",\n \"NSConstraintConflict (0x600003f42fc0) for constraint (\\n name\\n): database: 0x8143748c029ce8e1 <x-coredata://272191BB-7D10-41DD-8E4B-56F4ECE4AB9F/Ingredient/p101>, conflictedObjects:
This is just the initial part of the log; the above line is repeated many times, with different IDs of course.
To give you some context, the app has a list of Ingredients, which is seeded the first time the app is launched. I have a seed version constant, which is compared to a "seedversion" parameter, persisted to core data (and consequently cloudkit).
Ingredients has a constraint on the "name" property, which is a string.
I guess, for some reason, the seed was launched multiple times, and ingredients got duplicated; in plainer terms,I might have multiple instances of "cheese", deriving from different seeds.
I already have set the conflict merge policy in the NSPersistentCloudKitContainer initialization:
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
Yet I still get the error.
I looked at th docs and google for some suggestions, but I haven't found anything useful.
Any suggestion?
Cheers,
Davide