Frage

my application is another To-Do manager. It has class Todolist which can be local(private-list) or shared list. All data related to private-list is stored locally (Core Data + SQLite store). The data related to shared-list has to be stored both locally and remotely (so that all shared-list members are able to add their transactions to the list). Remote persistent store is backed with Parse Cloud via PFIncrementalStore. So my goal is to sync locally stored shared-lists to-dos with remotely stored to-dos.

here is a quote from Core Data Programming Guide:

A coordinator can only be associated with one managed object model. If you want to put different entities into different stores, you must partition your model entities by defining configurations within the managed object models

Does it means that I should create separate configuration of datamodel for shared-list and it's to-dos? Or simply reassign the object with method of NSManagedObjectContext- (void)assignObject:(id)object toPersistentStore:(NSPersistentStore *)store will be enough?

How I see the solution: when I'm dealing with shared list I assign it to PFIncrementalStore and on the other hand(dealing with private list) I assign it to standart local store (NSSQLiteStoreType).

Am I getting it right? Any suggestions are appreciated. Thank you.

War es hilfreich?

Lösung

Configurations aren't useful here unless either your local and remote to-dos are different entity types or you have other entities that should only exist in one of the persistent store files. When that quote refers to "different entities" they mean different entity types, not different instances of the same entity type.

What's more, you can't use assignObject:toPersistentStore: to move objects from one persistent store to another one. If you look at the docs for that method you'll see that it only applies to "a newly-inserted object". That means that if you create a new managed object that's not associated with any managed object context (i.e. one where you passed a nil value for the context when creating it), you can then tell NSManagedObjectContext to insert it into itself and to use a specific store file. Crucially, you cannot use this method on an object that already belongs to a context and a store, so you can't use it to move objects from one store to another.

To move objects as you describe, you'll need to do something like:

  1. Create a new instance in the target store
  2. Copy all attributes from the old object to the new one
  3. Delete the old one and save the new one

There's no built-in support for moving an object from one store to another.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top