Disable automatic iCloud sync with SwiftData

Is there a way to use SwiftData without automatic iCloud sync? I’d like to do that manually using my own CloudKit solution or CKSyncEngine. SwiftData automatically picks up any CloudKit containers though and I have not seen an option to disable this behavior. Setting cloudKitContainerIdentifier to nil does still pick the first available CloudKit container.

Just in case this is a bug: FB12276416

Sample:


let configuration = ModelConfiguration(cloudKitContainerIdentifier: nil)
        
let modelContainer = try! ModelContainer(for: [GamesCollection.self], configuration)
                
print(modelContainer.configurations)

// [SwiftData.ModelConfiguration(url: …, name: …, sharedAppContainerIdentifier: …, cloudKitContainerIdentifier: Optional("iCloud.CloudKit.com.+++")

From the WWDC Q&A

(Apple) answered: Simply do not use a CloudKit container identifier when configuring the SwiftData stack. There is currently a bug with this, so please file a feedback report.

I expect this will be fixed in the next Beta Release of Xcode.

Sadly still isn't fixed.

This is still an issue with iOS 17 beta 3.

  • Still an issue in iOS 17 beta 6.
  • "cloudKitContainerIdentifier" doesn't work anymore. You can't set nil or a value. You just get this error: "Extraneous argument label 'cloudKitContainerIdentifier:' in call"
  • Even though you can't set it, it still enables CloudKit on it's own. Making it impossible to disable it.

Still an issue in iOS 17 beta 7.

Although we can configure a ModelContainer with a cloudKitDatabase set to none, it still enables CloudKit and automatic sync on it's own.

ModelConfiguration(cloudKitDatabase: ModelConfiguration.CloudKitDatabase.none)

How is it possible that something as simple as turning off automatic syncing, which is part of the API, is not working in the RC version of Xcode 15, come on Apple...

This still seems busted in the Release Candidate

Same problem here, ModelConfiguration(cloudKitDatabase: .none) still uses CloudKit and the app crashes in my case with:

CloudKit integration requires that all relationships be optional, the following are not: Contact: addresses

Have to disable CloudKit capability to get it to run which is a terrible workaround.

Submitted FB13209319 referencing FB12276416

I have the same problem, with the same error as @malc. Did someone found a workaround?

Submitted FB13346018 referencing FB12276416.

Has anyone tried with the latest iOS 17.2 beta?

At first glance it's fixed as of iOS 17.2 beta 2, at least it does not crash any more with non-optional properties as it does on iOS 17.1 and below. I also don't see any attempts to sync in the console. So it seems like I can finally start bringing my app to SwiftData.

Is this an issue again? I previously ran into issues with migrating my schema to be CloudKit compatible and posted about it 2 months ago here: https://forums.developer.apple.com/forums/thread/744491. My solution I found was to disable CloudKit via the ModelConfiguration with CloudKitDatabase.none if it initially failed to load the ModelContainer. It allowed my data to go through the migration process first before attempting to sync with CloudKit. Everything was working fine, until just this week. I had a couple more crash reports show up. I reproduced it locally and sure enough, even with the CloudKitDatabase set to .none, it's crashing with an error CloudKit integration requires that all attributes be optional, or have a default value set.. It's not even throwing an error for me to catch, it's just crashing with Fatal error: 'try!' expression unexpectedly raised an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.loadIssueModelContainer) (my code doesn't use try! or any fatalError(), I only catch the error and attempt to gracefully fail with a user facing error message). It seems like iOS 17.4 might have broke this again? Can anyone else confirm?

Disable automatic iCloud sync with SwiftData
 
 
Q