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.

I found out part of my problem involving CloudKit, SwiftData and multiple AppleIDs.

It turns out that there is a setting in the Mac version of the AppStore app, called "Sandbox Account".

(This setting is not available on the Mobile versions of the AppStore app.) It appears that this setting is used to determine what AppleID is associated with an app when it is downloaded.

In my case, this setting was set to my old AppleID.

So when I loaded my app from the AppStore, it was associated with my old AppleID, which meant that CloudKit stored its synced data is my old AppleID's account. On the mobile side, this setting doesn't exist, so it appears that the AppStore uses the CURRENT AppleID. So my app was associated with one AppleID on the Macintosh and another AppleID on mobile devices. Hence incompatible data and no syncing.

Changing this setting on Macintosh and reloading fixes synching, but leaves me with a different problem —

  • before starting all this testing, I saved the SwiftData database from the Mac, which contained a bunch of information I want to retain.
  • I tried simply moving the database files into the Mac app's Application Support directory (in its sandboxed container). This resulted in being able to see and work with the data on the Mac, but it DID NOT SYNC.
  • Does anybody have any ideas of how to get this data out of the saved database and into the new (fully synced) database so that it is available on all of my devices? (Needless to say, I'm looking for something other than manually retyping all of the data.)

Any thoughts would be appreciated.

SwiftData, CloudKit and 2 AppleIDs
 
 
Q