Currently, I am planning to add a new feature to my app that allows multiple users to collaboratively manage a single legder. Initially, I chose SwiftData with iCloud for development, so I wanted to inquire whether SwiftData currently supports data sharing among multiple users through iCloud. If it does not, should I transition entirely to Core Data, or is it feasible to allow Core Data and SwiftData to work together?
SwiftData + CloudKit integration doesn’t support CloudKit sharing as of today.
I haven’t tried to implement SwiftData + CloudKit sharing with my own effort, but based on my understanding on the technologies, if the object graph to be shared is relatively complicated, I'd consider sticking with NSPersistentCloudKitContainer
(Core Data), because NSPersistentCloudKitContainer
interacts with Core Data, and using SwiftData adds another layer of complexity.
If the data to be shared is quite simple, such as a small set of values without relationships, and I have built my app with SwiftData, I might consider using CloudKit API directly to implement the sharing flow. That way, I completely control the synchronization and sharing process, and can share any data type, including SwiftData.
For the first option, you can start with the following sample:
The second option may turn out a bit involved. You can start with the technical resources mentioned in the following post:
Best,
——
Ziqiao Chen
Worldwide Developer Relations.