Unable to delete CKShare

Running the Apple sample code “Sharing Core Data objects between iCloud users” has presented the following challenge:

After the creation of a CKRecord in a Persistent CloudKit Container private database, the owner then shares it to a participant. All works fine. Then the Owner wants to stop sharing. That's fine too, although the CKRecord remains within the same shared zone within the owner's private database; it doesn't move back to the private database.

Then the owner wants to delete the CKRecord completely. Deletion of the record works, but evidence of the CKShare within the shared zone still remains inside the owner's private database.

It is clearly visible on the CloudKit dashboard. Probably doesn’t take up much memory but v messy and not cool.

How to delete this CKShare completely, leaving no trace? Any ideas would be most gratefully received!

Answered by DTS Engineer in 826605022

The behavior you described is as-designed.

If needed, you can choose to "move" the records back to the orignal record zone by creating a new managed object graph that is equivalent to those records, relate the graph to an un-shared managed object, and then save the managed object context. You can then call purgeObjectsAndRecordsInZone(with:in:completion:) with the shared record zone, which should delete the whole shared zone, including the CKShare instance.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

The behavior you described is as-designed.

If needed, you can choose to "move" the records back to the orignal record zone by creating a new managed object graph that is equivalent to those records, relate the graph to an un-shared managed object, and then save the managed object context. You can then call purgeObjectsAndRecordsInZone(with:in:completion:) with the shared record zone, which should delete the whole shared zone, including the CKShare instance.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Unable to delete CKShare
 
 
Q