Search code examples
iosswiftcore-dataicloudcloudkit

Cloudkit Coredata reset upon user logout iCloud


We have an iOS app which has Cloudkit Coredata as storage mechanism. Whenever user logout of iCloud in settings app, then the Coredata is wiped out and no row exists in the tables. Can we prevent this. We want to retain the Coredata values until there is another iCloud user logs into settings app.

Regards Vinoth


Solution

  • CloudKit data is linked to the user's account, and if you use Core Data's CloudKit support, that's where the data goes. It's not wiped out, it's in the user account, but without that account you can't see it.

    If you want CloudKit syncing and you want to keep the data available when someone logs out, you need to save a duplicate copy of the data outside of CloudKit. It's awkward to do, because it's not how Apple designed things to work. They don't design iOS devices for multiple users-- they see it as an individual device, so switching iCloud users is never simple.