SwiftData and CloudKit not synching between devices

Hi,

Not sure how to describe my issue best: I am using SwiftData and CloudKit to store my data.

In the past, when I tested my app on different devices, the data would sync between the devices automatically. For whatever reason this has stopped now and the data no longer syncs. No matter what I do, it feels as if all the data is actually stored just locally on each device.

How can I check if the data is actually stored in the cloud and what could be reasons, why its no longer synching between my devices (and yes, I am logged in with the same Apple ID on all devices).

Thanks for any hint!

Max

Answered by bobandsee in 863156022

I believe I found the root cause: I had 2 entitlements files, one called

ExpensesTest.entitlements

and the other

ExpensesTestRelease.entitlements

The latter had the information about the CloudKit container in it while the other was missing those entries. After creating a new container and adding those values manually to

ExpensesTest.entitlements

it nows works like a charm again.

Just to add that SwiftData + CloudKit uses NSPersistentCloudKitContainer under the hood, and so the technotes my colleague mentioned apply to your topic. Specifically, you can use CloudKit Console to determine if the data is synchronized to CloudKit. From there, you can determine if the issue happens on the exporting or importing side, and go ahead to capture and analyze a sysdiagnose, as described in the Capture and analyze a sysdiagnose section.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

How can I check if the data is actually stored in the cloud

https://icloud.developer.apple.com/dashboard

The steps are detailed here in the mentioned technote section.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Thanks for all the advice! I just checked in the dashboard and even there I cannot even see the schema or any record types of my SwiftData model. The only record type that exists is "Users".

I have already created a new container but that does not seem to make any difference. What could the reason be that not even the data model is pushed to CloudKit?

Accepted Answer

I believe I found the root cause: I had 2 entitlements files, one called

ExpensesTest.entitlements

and the other

ExpensesTestRelease.entitlements

The latter had the information about the CloudKit container in it while the other was missing those entries. After creating a new container and adding those values manually to

ExpensesTest.entitlements

it nows works like a charm again.

SwiftData and CloudKit not synching between devices
 
 
Q