I have created two context like this:
// create writer MOC
_privateWriterContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[_privateWriterContext setPersistentStoreCoordinator:_persistentStoreCoordinator];
// create main thread MOC
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
_managedObjectContext.parentContext = _privateWriterContext;
I have a NSFetchResultedController
initiated with _managedObjectContext
.
I know it is strange, but I am adding a record to the parent to _privateWriterContext
, I am saving
it.
What is surprising is that child context and so FRC
gets notified about this event. Why? I have not reset
-ed child, or anything else. I thought they are independent entities as long as child context will not get saved.
In @pteofil article I found this line:
When a change is made in a context, but not saved, it is visible to all of its’ descendants but not to its’ ancestors.
.. it is pushed to the persistent store (via the persistent store coordinator) and becomes visible to all contexts connected to the store.
NSManagedObjectContextDidSaveNotification
and merge changes from notification if I am using two context joining to the same PSC configuration – AudetNSManagedObjectContextDidSaveNotification
to merge changes between them? – AnhinitWithConcurrencyType
but withinit
, and then this statement in article will not take place, it is pushed to the persistent store and becomes visible to all contexts connected to the store. – AudetNSManagedObjectContextDidSaveNotification
with nested contexts. The parent-child relationships replace notifications as a change distribution mechanism, mixing the two can cause problems. – Month