What's a general procedure to combine SwiftData and CloudKit?

I have already built an app using SwiftData and now I want to introduce CloudKit features in it, what should I do? I'm totally new to this part. Thank you!

Answered by DTS Engineer in 817341022

To implement SwiftData + CloudKit, here is what you need to do:

  1. Configure CloudKit for your app. This is covered in Configuring iCloud services, and is also discussed in Configure iCloud on your devices and Configure CloudKit in your project.

  2. Specify the CloudKit database when creating the model configuration for your model container. If your app uses only one CloudKit container, the default value of the cloudKitDatabase parameter, .automatic, should just work. Otherwise, use .private(_:) to specify the right CloudKit container.

Only CloudKit private database can be integrated with SwiftData as of today, as mentioned here.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

To implement SwiftData + CloudKit, here is what you need to do:

  1. Configure CloudKit for your app. This is covered in Configuring iCloud services, and is also discussed in Configure iCloud on your devices and Configure CloudKit in your project.

  2. Specify the CloudKit database when creating the model configuration for your model container. If your app uses only one CloudKit container, the default value of the cloudKitDatabase parameter, .automatic, should just work. Otherwise, use .private(_:) to specify the right CloudKit container.

Only CloudKit private database can be integrated with SwiftData as of today, as mentioned here.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

What's a general procedure to combine SwiftData and CloudKit?
 
 
Q