SwiftData with shared and private containers

I was hoping for an update of SwiftData which adopted the use of shared and public CloudKit containers, in the same way it does for the private CloudKit container.

So firstly, a big request to any Apple devs reading, for this to be a thing!

Secondly, what would be a sensible way of adding a shared container in CloudKit to an existing app that is already using SwiftData?

Would it be possible to use the new DataStore method to manage CloudKit syncing with a public or shared container?

Answered by DTS Engineer in 790189022

SwiftData + CloudKit public or shared database isn't supported today. If that is critical to your app, I suggest that you file a feedback report to voice your need.

The framework, including the new DataStore API, doesn't provide supports in that regard. You can choose to implement your own way, similar to what NSPersistentCloudKitContainer does, but that will be obviously very involved.

I'd probably stick with NSPersistentCloudKitContainer, if I do need the integration with CloudKit public or shared database.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

SwiftData + CloudKit public or shared database isn't supported today. If that is critical to your app, I suggest that you file a feedback report to voice your need.

The framework, including the new DataStore API, doesn't provide supports in that regard. You can choose to implement your own way, similar to what NSPersistentCloudKitContainer does, but that will be obviously very involved.

I'd probably stick with NSPersistentCloudKitContainer, if I do need the integration with CloudKit public or shared database.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

This is disappointing. I had really hoped this WWDC would bring the announcement that SwiftData now supported collaboration. I had already filed FB requesting this (FB13801092, not that long ago, alas), but honestly I'm surprised Apple wasn't already working on this.

When you introduce new technologies that are meant to replace older ones, you really need to follow up quickly with replacement for all the older functionality.

18

I just wanted to add a message of support here for this feature request. I've also filed a feedback report.

PoC using SwiftData looked great; then client says "I need databases shared". I think, this will take less than an hour... I hope some AI will understand "roll this back to Core Data and NSPersistentCloudKitContainer".

@DTS Engineer , does swift data support this now after the latest release of IOS?

Yes, SwiftData is great, but until it is only marginally useful if we can't easily sync data across devices or share data with other users.

+1 for shared data support. I want to implement a sync mechanism, and considered using SwiftData, but need to to work for multiple users. So I guess I'll have to go with old-style CloudKit.

+1 for shared data support.
Please update an iOS18 & SwiftData version for CloudKit Sharing in this repository: https://github.com/apple/sample-cloudkit-sharing

SwiftData with shared and private containers
 
 
Q