Merging multiple child managed object contexts

In my iOS application, I am attempting to sync core data with a web back end. I want to use a separate background managed object context for the sync so I can keep my main context free to accept changes from the ui while the sync is processing. Both contexts are children of my write-to-disk context as per this blog post

My question is, how can I merge both children contexts before I save to disk?

If I subscribe to contextDidSaveNotifications, I can merge the contexts using

[mainContext mergeChangesFromContextDidSaveNotification:syncFinishedNotification];

but according to the documentation…
“This method refreshes any objects which have been updated in the other context, faults in any newly-inserted objects, and invokes deleteObject:: on those which have been deleted.”

I don’t want to refresh the updated objects and lose changes made to the mainContext, but rather merge both change sets.

I am new to multi-context core data, so I may be thinking of this in the wrong way.

Any ideas?

Leave a Reply