CoreData sharing/collaboration feature is broken

On top of unstable CloudKit sync, we've got also extremely unstable sharing/collaboration functionality.

I mean, it's quite impressive how easy it is to enable sharing, but this feature should not be released at this point. It feels like using software in the alpha version.

Let's take NSPersistentCloudKitContainer.share(_:to:) (https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontainer/3746834-share), the documentation says:

Sharing fails if any of the following conditions apply:

  • Any objects in managedObjects, or those the traversal finds, belong to > an existing share record.

However, it's wrong... if you pass any object from the existing share, it will return the same share... It never fails in this case.

Things are getting even weirder if you experiment a little bit with shares. So let's assume you share a couple of objects:

persistentContainer.share([A, B, C, D], to: nil)

Now you stop sharing those via UICloudSharingController and you want to share again but just C. So you call:

persistentContainer.share([C], to: nil)

and surprise, surprise, you get a new share URL, but you share all previously shared objects (A, B, C, D), not as you would have expected only C...

On top of that, you keep getting some weird errors like:

error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _requestAbortedNotInitialized:](2190): <NSCloudKitMirroringDelegate: 0x3029b84b0> - Never successfully initialized and cannot execute request '<NSCloudKitMirroringExportRequest: 0x30359f1b0>123123123123' due to error: <CKError 0x3018699b0: "Partial Failure" (2/1011); "Failed to modify some record zones"; uuid = 12312312312312; container ID = "iCloud.some.id"; partial errors: {
	com.apple.coredata.cloudkit.share.123123123123123:__defaultOwner__ = <CKError 0x30186a3d0: "Invalid Arguments" (12/2006); server message = "Only shared zones can be accessed in the shared DB"; op = 12312312312312; uuid = 123123123123>
}>

Even though the only thing I use is

persistentContainer.share

and

UICloudSharingController(share: share, container: cloudKitContainer)

And the cherry on the top, from time to time if you play a little with sharing multiple objects at once, it happens that it randomly wipes out some records from that share...

I don't even know where to start reporting issues and if its worth it, because every ticket will be dismissed anyway because "we need thousands of your logs, we require you to do all the job for us".

I've often wondered how NSPersistentCloudKitContainer.share… works, and your example goes a long way to explaining it. When you identify the objects you want to share, they get moved to a new zone. and that zone is what is shared. but the API probably wasn't designed to handle the scenario you describe, so once a record is moved to a shared zone, it doesn't/can't get move to another zone. 2¢

CoreData sharing/collaboration feature is broken
 
 
Q