I have a root object (e.g. CD_RootObject) with one-to-many relationships to another object (e.g. CD_RelationObject) and am sharing records between users through custom zone (sharing multiple root records in the zone).
Recently, my users (on iOS 17.5.1 and iOS 17.6 beta) are reporting that they have problem syncing records with other devices (device from same iCloud Account, and also with device with different iCloud Account). One user informed us the error:
“XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX’ was aborted because the mirroring delegate never successfully initialised due to error: Error Domain=NSCocoaErrorDomainCode=134060 “A Core Data error occurred.” UserInfo={NSLocalizedFailureReason=Object graph corruption detected. Objects related to ‘0x???????????????? x-coredata://XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/[CD_RelationObject]/p588’ are assigned to multiple zones: {(CKRecordZoneID: 0x3026a1170; zoneName=com.apple.coredata.cloudkit.share.XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX, ownerName=_defaultOwner>,<CKRecordID:0x302687b40; zoneName=come.apple.coredata.cloud-kit.zone,ownerName=_defaultOwner>…)}}
When saving my CD_RelationObject, I always read out the CD_RootObject first, and then set the relationship to CD_RootObject from CD_RelationObject, update CD_RelationObject and save context.
From my understanding, if the CD_RootObject is moved to the custom zone, every record in the hierarchy below the root will be automatically moved to the same custom zone. It seems that some records are somehow assigned to the default private zone in additions to the custom zone.
Questions:
(1) How can I fix the core data object graph corruption?
(2) Is there a way to read out all the records which are assigned to multiple zones and delete them from the default zone (so that they reside only in the shared zone)?