drewmccormack / ensembles

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

Batched Traversals & hasChanges #175

Closed asciiz closed 10 years ago

asciiz commented 10 years ago

When using batched traversals: persistentStoreEnsemble:shouldSaveMergedChangesInManagedObjectContext:reparationManagedObjectContext:

is called each time before: persistentStoreEnsemble:didSaveMergeChangesWithNotification:

As described in the book, I cancel the merge in "shouldSaveMergedChangesInManagedObjectContext" when there are unsaved changes.

When using batched traversals, this doesn't work because "hasChanges" frequently returns YES once mergeChangesFromContextDidSaveNotification: has been called (and something has changed).

drewmccormack commented 10 years ago

Thanks. I'm going to look into it.

drewmccormack commented 10 years ago

I've looked into it now, and I can't see the problem, to be honest. When a batch is saved, it updates the persistent store, and you should merge the changes using the notification into your main context. But that does not cause hasChanges to be YES, because hasChanges should only be YES when the context has values differing from those in the store.

If you are seeing that hasChanges is YES when you don't expect it to be, you can check the updatedObjects etc to determine what exactly the changes are.

If you disagree with me, can you be more concrete about how you think saving in batches is changing your main context hasChanges to YES?