Search code examples
iosswiftcore-datacloudkitnspersistentcloudkitcontainer

Storing some entities only locally when using NSPersistentCloudKitContainer


What I want to achieve is that I have a Core Data configuration that syncs with CloudKit and a configuration that does not get synced. There are some entities I don't want to sync. They should be stored locally only.

I've tried to create a separate configuration and unchecked Used with CloudKit. Now if I'm adding a new entity that should only be used by the local configuration it is always in the default configuration (that is synced with CloudKit) as well. I can't remove the entity from the default configuration though.

enter image description here

In that case Entity is also in the default configuration and therefore would get synced with CloudKit.

How can I achieve to store this entity only on the device?


Solution

  • The documentation for your use case is here: https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/setting_up_core_data_with_cloudkit

    This documentation suggests, at the end, that you create two configurations, one to sync with CloudKit, and one without. It looks like the default configuration is not synced with Cloudkit.