Why might changes be populated from one NSManagedObjectContext to another without an explicit merge?
Posted
by Mike Laurence
on Stack Overflow
See other posts from Stack Overflow
or by Mike Laurence
Published on 2010-03-18T19:57:27Z
Indexed on
2010/03/18
20:01 UTC
Read the original article
Hit count: 778
core-data
|nsmanagedobjectcontext
I'm working on an object import feature that utilizes multiple threads/NSManagedObjectContexts, using http://www.mac-developer-network.com/columns/coredata/may2009/ as my guide (note that I am developing for iPhone).
For some reason, when I save one of my contexts the other is immediately updated with the changes, even though I have commented out my calls to mergeChangesFromContextDidSaveNotification. Are there any reasons the contexts might be merging into one another without an explicit call?
Here a log of what's going on:
// 1.) Main context is saved with "Peter Gabriel"
// 2.) Test context is created, begins with same contents as main context
// 3.) Main context is inserted with "Spoon"
// 4.) Test context is inserted with "Phoenix"
// Contents at this point:
CoreTest[4341:903] Artists in main context: (
"Peter Gabriel",
"Spoon"
)
CoreTest[4341:903] Artists in test context: (
"Peter Gabriel",
"Phoenix"
)
// 5.) testContext is saved
// New contents of contexts:
CoreTest[4341:903] Artists in main context: (
"Peter Gabriel",
"Phoenix",
"Spoon"
)
CoreTest[4341:903] Artists in test context: (
"Peter Gabriel",
"Phoenix"
)
As you can see, the test context is saved midway through, and the main context suddenly has the new objects from the test context, even though I haven't performed the whole NSManagedObjectContextDidSaveNotification/mergeChangesFromContext combo.
My understanding is that no changes will ever be merged unless done so explicitly... does anyone know what's going on here?
© Stack Overflow or respective owner