SwiftData, CloudKit and 2 AppleIDs

I have a SwiftData app that runs on iOS, iPadOS, and MacCatalyst and which uses CloudKit for inter-device sync. Unfortunately, I also have two AppleIDs (which I 'll refer to as OLDID and NEWID).

Although all three devices (phone, pad and desktop) are currently set up with NEWID as the active AppleID, during development and testing, my desktop Mac used OLDID. Apparently, the system remembers the AppleID to use with each CloudKit app (based on the AppleID active at time of first use), because the desktop app and the mobile apps apparently sync to different AppleID accounts.

I can delete the local database on the desktop and delete the local app on the mobile devices and in each case, reloading/rerunning the app causes the respective databases to be restored from the cloud. The two mobile devices sync with each other, but not with the desktop; the desktop doesn't sync with either device. And the two databases have decidedly different contents.

My goal is to consolidate everything so that there is one database, shared and synced between desktop, pad, phone and cloud.

I presume that there is a setting somewhere (but clearly NOT in the app's sandboxed container) that specifies what iCloud account to use for that (and each) app.

Note: I have other apps which sync between all my devices, so the setting must be on a per-app basis.

I also presume that if I changed it's value on my desktop (so that all three devices used the same AppleID for cloud services for my app), that the content of the local database on my desktop would be synced automatically to the NEWID cloud account and then (also automatically) synchronized with my mobile devices.

I.e., I speculate that I can solve all my problems by changing that setting on my desktop Mac.

So I have two questions:

  1. Is all this correct?
  2. How do I make this setting change. (I.e., where is it and how do I change it)

Does anyone have any experience and can help with this issue?

Thanks

This is worth a feedback report with a sample app and a set of instructions to replicate your workflow.

At a high level SwiftData / NSPersistentCloudKitContainer take great pains to prevent surfacing data to different logical iCloud accounts. So as a practical matter attempting to do that is not a supported use case.

I understand the issues you have raised, and I can certainly see that there are pretty obvious security concerns in publicizing the use case.

I will put together a feedback report about this and address these issues privately. The app in question is one which I wrote for myself (and offered to others who might be interested) — there ought to be a way that I can actually get to use my own app (i.e., synched between my own devices)...

I'll post the FB number to this thread ASAP.

SwiftData, CloudKit and 2 AppleIDs
 
 
Q