Leaving/Stopping CKShare using CoreData

Hello,

I am working with sharing over Core Data. I would like to implement my own UI to share records and manage participants. In the CKShare's documentation we can read:

However, only the owner can delete a shared hierarchy’s root record. If a participant attempts to delete the share, CloudKit removes the participant. The share remains active for all other participants (https://developer.apple.com/documentation/cloudkit/ckshare).

However, when I delete a shared NSManagedObject (as a participant), using self.moc.delete(sharedProject), the object is deleted even for its owner.

On the other hand, accoring to the "Sharing Core Data objects between iCloud users" documentation (https://developer.apple.com/documentation/coredata/sharing_core_data_objects_between_icloud_users), to delete a share, we should use the purgeObjectsAndRecordsInZone(with:in:completion:) method. And that works, however, NSManagedObjectContext doesn't merge changes. Moreover, in the same documentation we can read:

Manages the participants of the share from the owner side using addParticipant(:) and removeParticipant(:), or stops the sharing by calling purgeObjectsAndRecordsInZone(with:in:completion:).

Unfortunately, calling that method from the owner side leads to deletion of the shared record.

Do you have any ideas how to receive a similar effect like in the UICloudSharingController?

Leaving/Stopping CKShare using CoreData
 
 
Q