drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

Multiple contexts #152

Closed cflorion closed 10 years ago

cflorion commented 10 years ago

Does Ensemble work in a multiple ManagedObjectContexts app ? I can't make it work so far.

I use MagicalRecord (MR) to setup my Core Data stack. By default MR creates 2 contexts:

Which one should Ensembles know about ? The root or default ?

My code looks like that: [MagicalRecord setupCoreDataStackWithStoreNamed:@"store.sqlite"]; IDMSyncManager *syncManager = [IDMSyncManager sharedSyncManager]; syncManager.managedObjectContext = defaultContext; syncManager.storePath = [defaultContext.persistentStoreCoordinator.persistentStores.firstObject URL].path; [syncManager setup];

Thanks !

cflorion commented 10 years ago

I got rid of MagicalRecord method setup the Core Data stack and it's working... I don't understand the difference between manual setup and MagicalRecord one, weird.

But I still have this interrogation, is this a bad idea to use the root context for Ensemble ? This would mean that that changes would be synced by Ensembles only when the data changes get to the root context, and not at each save to the main context right ?

drewmccormack commented 10 years ago

Ensembles only observes contexts that save directly into the store. Any others are ignored, because they don't modify the store.

There are some gotchas with MR and using background async. The book goes into quite a bit of detail on how to handle it.

drewmccormack commented 10 years ago

One thing to be aware of is that you will likely have to mergeChanges... into both of your contexts. Again, the book covers this aspect.

cflorion commented 10 years ago

"Ensembles only observes contexts that save directly into the store" Good to know !

I just bought the book, this will be much easier thanks !