NSPersistentCloudKitContainer for Shares

Does anyone know if the new NSPersistentCloudKitContainer will work in an Application that shares data with others (CKShare), or will it only work as shown in the demo with other devices of the same iCloud Account?

Answered by Frameworks Engineer in 376835022

NSPersistentCloudKitContainer does not support sharing. Please file a feedback report with your intended sharing use case, data model, and any specific design requirements you have regarding the sharing experience.


As others have (correctly) pointed out, NSPersistentCloudKitContainer maintains a specific zone in the private database, and therefore will never see any shared zones owned by other users.


You can implement sharing yourself using the standard CKShare / CKRecord APIs.

I didn't see that before. Thanks. Does that mean the system will take care of syncing changes between owner and share recipients with core data on each participants devices under iOS 13? Or would it have to be handle like it today by manually updating Core Data once the notification comes in about changes?

NSPersistentCloudKitContainer only syncs to a private database, according to the published docs. No mention of public or shared CKDatabase.

That's what I was afraid of. Too bad. It seems like a logic follow on to what they have started here. Thanks, I wanted to see if I was missing something. My App has cloudkit sharing as a core feature so this won't be applicable to me at this time. :-(

I've been waiting on CloudKit + CoreData integration for a while, and I don't see how NSPersistentCloudKitContainer can't be used to share. Zero of my users has asked to sync the data between devices, everyone wants to share it between users, and how is such a core feature missing?


Have to say, I'm not sure if it's missing because I can't find any documentation or tutorials, but it sure looks that way!

The presenter at WWDC 2019 (Nick Gillett) mentioned that Apple maintains a custom Zone in the private database (around 10:50 in the video).

Since records get saved in the private database, I would think that CKShares and NSPersistentCloudKitContainer are a no-go combo.


But, according to Apple's documentation, you can access the CKRecord for a specific managed object using dedicated methods, which will allow you to create CKShares: https://developer.apple.com... So I am confused.

Agreed, I read the docs to mean that sharing is possible but I’m not able to use NSPersistentCloudKitContainer methods that return CKRecords based on managed objects at this time. I am hoping this is just due to early beta issues.

Accepted Answer

NSPersistentCloudKitContainer does not support sharing. Please file a feedback report with your intended sharing use case, data model, and any specific design requirements you have regarding the sharing experience.


As others have (correctly) pointed out, NSPersistentCloudKitContainer maintains a specific zone in the private database, and therefore will never see any shared zones owned by other users.


You can implement sharing yourself using the standard CKShare / CKRecord APIs.

Hi Nick,


Thank you for your response. I have submitted a feedback request as you mentioned. Feedback - FB7035351, I also submitted one on June 11th, FB6146466 on the same subject. Both are marked as open. The latest one FB7035351 has more details.


Love what you guys are doing!


Thanks,


Rob

Hi Nick,


The NSPersistentCloudKitContainer is awesome and works great, but I also have a requirement to share the data and keep the share in sync. My question, though, is when I use the record function to get my root object, and then create a CKShare for that object, how can I also share its 1-many relationships, since they are not true CKRecord.Reference objects according to the docs. Is there a way for me to get those relationships or am I misunderstanding things.


Thanks!

Mike

Hi - I am trying to make this work as you suggest by "...You can implement sharing yourself using the standard CKShare / CKRecord APIs..."


But how can you implement the CKShare that shares more than a single entity. A parent detail senario for example. How can I set the CKRecord Parent relationships such that I can share a family of reocrds from different but related files?


Thanks,


Rob

Yes, I am looking for that feature too. I have many apps would like to share some of the data amount them.

I am missing this feature too. I hope that wwdc20 will give som answers.
WWDC20 did it!

Code Block
let containerIdentifier = persistentStoreDescriptions.cloudKitContainerOptions!.containerIdentifier
persistentStoreDescriptions.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: containerIdentifier)
persistentStoreDescriptions.cloudKitContainerOptions?.databaseScope = .public
     


But, when could we really using it in apps?
I've also added a feature request to support this (FB9052948). It would be amazing to see it happening on next WWDC!
NSPersistentCloudKitContainer for Shares
 
 
Q