I have Core Data setup with a NSPersistentCloudKitContainer
as my container, I've added a container identifier and I see my data on CloudKit's database here when I use "Act As iCloud Account". Here's what I have under capabilities in Xcode
However, on my device when I go to Settings > Apple Account > iCloud > Saved to iCloud and switch off my app, all the data saved to Core Data is removed. I suspected this working as intended. When I switch it back on, all the data comes back. However (x2), the support page here says it should remain on the device:
When you turn it off, the app no longer connects with iCloud, so your data exists only on your device
Am I missing something in how I integrated Core Data in Xcode? Do I need to explicitly configure something with Apple's SDK to get the behavior described in the support page?
I've noticed for some of Apple's apps, when you switch off iCloud there's an action sheet asking what you'd like to do with the local data. I figured this was Apple's magic without sharing especially since the buttons looked different
However (x3), not all apps that had this option offered "Keep on My iPhone", so perhaps the supported behavior is to remove what's on the device and these Apple apps implemented their own support to keep a copy on the device.
I've tried testing some 3rd-party apps but couldn't convince myself they were using Core Data with iCloud enabled. Instead, it looked like they were using iCloud as a backup
"However, on my device when I go to Settings > Apple Account > iCloud > Saved to iCloud and switch off my app, all the data saved to Core Data is removed. I suspected this working as intended. "
Yeah, this is an as-designed behavior. Basically, NSPersistentCloudKitContainer
removes the local data from the device in that case for privacy reason, and it doesn't expose any API for developers to configure the behavior.
I discussed the behavior NSPersistentCloudKitContainer
responds to user switching in the following post:
From user's perspective, switching to a new user may be different from disabling the Saved to iCloud
setting, but CloudKit doesn't handle the two cases in a different way, as far as I know.
Having said that, if you believe that NSPersistentCloudKitContainer
shouldn't behave that way, please file a feedback report with your concrete use case – If you do so, please share your report ID here.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.