Sync SwiftData via CloudKit on App Start

I have an app that uses SwiftData with CloudKit to synchronize data across a users devices. I'm able to replicate data created on one device on another and when removing data, it is also removed on the other device. So, I know that SwiftData and CloudKit are configured correctly.

What I'd like to do though, is to ensure that if a user installs the app on an additional device, that the data is synchronized upon app start.

When testing my app on a third device, via TestFlight, there was no data in the app upon launch even though all three devices are using the same Apple account (e.g. Apple ID).

What is the best way to achieve this?

Answered by dougholland in 814926022

I hadn't used CloudKit before and didn't realize the additional steps required to deploy the container into production. I should be able to resolve this issue now before the next TestFlight release.

I think, The default configuration of SwiftData and CloudKit meets your needs

I think this maybe caused by the other two devices using the development container and the third device, which never had a development build, using the production container. All three are using an Apple ID from the internal testing group and so I would have thought all three should be on the same container.

Accepted Answer

I hadn't used CloudKit before and didn't realize the additional steps required to deploy the container into production. I should be able to resolve this issue now before the next TestFlight release.

If anyone else runs into this issue, I recommend looking at this article: Deploying an iCloud Container's Schema.

Sync SwiftData via CloudKit on App Start
 
 
Q