How to stop SwiftData syncing with CloudKit
How to stop SwiftData syncing with CloudKit 관련
Updated for Xcode 15
As soon as you enable CloudKit support for your app, SwiftData will automatically start syncing your local data with iCloud. If this isn't what you want – if you'd rather handle syncing by hand using CKSyncEngine
or similar – then in theory you should be able to create a custom model configuration to disable automatic syncing.
I say "in theory" because in my tests this doesn't actually work. At the time of writing, there is no way of enabling iCloud support for your project without SwiftData automatically syncing its data there.
If this problem gets resolved, the following should work to disable iCloud syncing:
do {
let config = ModelConfiguration(cloudKitDatabase: .none)
container = try ModelContainer(for: Restaurant.self, configurations: config)
} catch {
fatalError("Failed to create model container.")
}
That sets the CloudKit database to .none
, which should mean no automatic syncing takes place. Again, this doesn't work at the time of writing, but hopefully that will get fixed soon enough…