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: NSPersistentCloudKitContainer losing data 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
Topic:
App & System Services
SubTopic:
iCloud & Data
Tags: