Hello everyone,
I've really been enjoying SwiftData's approach to handling DBs, however sharing data between users has caused me quite some headaches.
I am currently developing an app for my local theatre that will help the assistant directors with production planning and would need a way to share data. On some big productions we have 2 ADs, so they'd need to be able to share the project and do collaborative work on it. I don't need fancy real-time editing or anything. However, SwiftData exposing an equivalent to Core Data’s NSPersistentCloudKitContainer sharing APIs for CKShare-based user-to-user collaboration would be amazing.
As the only thing supported is per-user private data sync, I’m currently considering a hybrid approach until the full project could be shared:
- SwiftData for the main private app data
- a small separate Core Data + CloudKit sharing stack only for the shared timetables for cast and crew
Is that the recommended implementation today, or is there a better SwiftData-friendly way to do this?
I also filed Feedback Assistant request FB22712510 asking for native SwiftData support for user-to-user CloudKit sharing.
Thanks for any pointers or help!
Best regards, Aedan
I will be a bit worrying. SwiftData + CloudKit uses NSPersistentCloudKitContainer under the hood, and if you create a NSPersistentCloudKitContainer stack for sharing, your app may have two NSPersistentCloudKitContainer instances doing the synchronization, which can run into trouble, as mentioned here.
If the data to be shared is simple, I'd probably consider using CloudKit API directly. See here to get started.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.