Search code examples
iosobjective-ccore-dataswifticloud

Syncing only one entity in Core Data to iCloud


I'm an iOS developer experimenting with iCloud and Core Data for a feed reader application. I have Core Data set up for two entities, one for an Item and another for a Channel. The Channel entity contains the information that I would use to have a user's subscribed websites synced to all their devices. In my own research, I have only found a way to sync both entities in Core Data. My question is: is it possible to sync only one Core Data entity to iCloud?

I can post my code if it would help.


Solution

  • Is it possible to sync only one Core Data entity to iCloud?

    Only if they're stored in separate persistent store files.

    You configure iCloud by passing options to addPersistentStoreWithType:configuration:URL:options:error:. Once you do that, everything in the persistent store is synced to iCloud. There's no per-entity configuration for iCloud.

    However, NSPersistentStoreCoordinator can have multiple persistent stores. You add more than one, with different paths, and you don't have to use the same options on all of them. You can't have relationships that cross persistent stores, but you can have fetched properties. That's not quite the same, but in some cases it's a workable replacement. They'll give you a unidirectional way to look up one or more objects and return them as if they were a property value. The example mentioned in the docs for fetched properties is something like an iTunes playlist, which might be similar to your situation.

    So: yes, sort of, if you're willing to do some extra work to make it happen.