Use CoreData alongside SwiftData for the "Sharing" feature in the app.

Hello! 😊

I currently manage an app called MoneyKeeper that uses SwiftData for its data storage framework. Many users have requested a "sharing" feature, but unfortunately, SwiftData does not yet support this functionality, and it’s unclear when it will. 😭

Initially, I considered using CloudKit and CKSyncEngine to implement quick synchronization and sharing. However, due to the complexity of the current data model’s relationships, modeling it with CloudKit’s schema alone seemed overly complicated and likely to introduce bugs.

As a result, I’ve decided to implement the sharing feature using CoreData and CloudKit. My plan to avoid conflicts with SwiftData includes:

  1. Keeping the local storage locations for SwiftData and CoreData separate.
  2. Using entirely separate CloudKit containers for SwiftData and CoreData.

I believe these measures will minimize potential issues, but I’m wondering if there’s anything else I should consider.

Using both SwiftData (for the personal database) and CoreData (for the shared database) feels like it could lead to significant technical debt in the future, and I anticipate encountering even more challenges during actual implementation.

I’d greatly appreciate your valuable insights on this matter. 🙏


The app MoneyKeeper, currently operated using SwiftData. https://apps.apple.com/app/id6514279917

Before SwiftData supports CloudKit sharing integration, my opinion in this regard was mentioned in the following post:

Regarding your plan, using CoreData alongside SwiftData should be fine, as demonstrated in the following sample:

The question will be if you can indeed separate the Core Data store and SwiftData store effectively. In most cases, there will be connections between the two stores, and so you will need some bridging code for data access and transformation.

If you use Core Data for CloudKit sharing, you will use Core Data for CloudKit private database synchronization as well (because CloudKit sharing is about sharing data in a CloudKit private database, and so you might not need to back your SwiftData store with a "separate" CloudKit container.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Use CoreData alongside SwiftData for the "Sharing" feature in the app.
 
 
Q