CoreData + CloudKit but No sharing

394 views Asked by At

CoreData is pretty awesome. It makes coding a persistent store with a SQLite DB quite predictable.

CloudKit is pretty awesome. It makes coding a persistent store in iCloud easy and shareable between a user's devices.

CoreData + CloudKit are doubly awesome since it brings the advantages of both a local data store and sharing between devices.

Now, I'm completely dumb founded and surprised by the fact that Apple does not support CloudKit sharing between users when using CoreData + CloudKit. Every time I raise this question, people look at me like why would someone want this? I'm confused. Is there a reason why one wouldn't want to leverage a local + cloud synced shareable combination of storage?

It would be super useful if someone can help me understand why this doesn't exist or why I wouldn't want to design storage that incorporates Local persistence with synchronization to the cloud and the ability to share those objects between users?

2

There are 2 answers

0
Fattie On BEST ANSWER

Justin, if I understand your point, you're 100% correct,

"Now, I'm completely dumb founded and surprised by the fact that Apple does not support CloudKit sharing between users when using CoreData + CloudKit..."

Sync is just very hard.

"The" major technological cornerstones of the era we live in are Parse (the guys who programmed it deservedly made trillions of dollars), Firebase, and the sync services offered by AWS and Goog-services.

And the many other sync competitors like Couchbase, ably.io, realm.io, and similar backbones like pubnub.

Sync is literally the major internet backbones of the day.

(The biggest services - TikTok, Twitter - are nothing more than what you ask for, sync services, with a few buttons and logos added on top.)

CFRD and other approaches are very very very hard indeed as a computer science matter (https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) , and it's mindbogglingly difficult from the hardware and wires up at scale.

So you're basically saying "When oh when will Apple hurry up and make a sync backbone so I can finally stop using {Firebase, AWS or whatever your poison is}..."

You're right.

(And don't forget, one issue is, we live in the duality world of droid-iphone. No client's going to hire you to build the next tiktok for dogs, facebook for dogs and it will be "just iOS". If Apple make their own sync service, it will be dead on arrival, the most pointless white elephant in creation, unless it is ios, droid, www and also the minor-majors like unity etc.)

If I understand your question, yeah, I guess it's just a matter of time. But (like any of the sync backbones) it will have to be all-platform.

Don't even mention with iot, apple glasses etc etc.

0
Ben On

Agreed all around.

As you mention, NSPersistentCloudKitContainer does not support sharing in iOS 13, but due to lots of feedback requesting this it is being added this year (currently in beta). Here's the WWDC20 talk on the public database specifically: https://developer.apple.com/videos/play/wwdc2020/10650/.

The starting point here is through NSPersistentCloudKitContainerOptions.databaseScope.

In the meantime, if you need sharing right now before this stuff is released, you can access the CKRecords directly possibly to implement sharing yourself without having to rebuild the whole CloudKit implementation. Kind of fuzzy, but the first paragraph of this doc states that explicitly, just with no details on how a CKShare works into Core Data syncing.