Skip to content
DeveloperMemos

Disabling Automatic iCloud Sync in SwiftData

Swift, SwiftData, iCloud1 min read

Lately, I've been fiddling around with SwiftData quite a bit. I have read about people on Twitter experiencing some issues with it, but I've just started out with something really small to test it out.

I hadn't actually tested the iCloud Sync aspect of the framework yet in my new project, so I decided to sign into an Apple ID on the simulator and see if it actually worked. It did, almost like magic.

That got me thinking, what if you don't want automatic iCloud sync out of the box? You can easily disable the functionality.

When creating your configuration using ModelConfiguration, you just need to specify .none for cloudKitDatabase:

1let config = ModelConfiguration(cloudKitDatabase: .none)
2let modelContainer = try ModelContainer(for: ModelA.self, ModelB.self,
3 configurations: config)

And that's all there is to it. You can also specify an existing iCloud container like this:

1let config = ModelConfiguration(cloudKitDatabase: .private("iCloud.com.existing.Container"))

I'm not entirely sure about migrating to SwiftData, though, especially given the strict iOS 17+ requirement.

Anyway, as always, happy coding!