NSManagedObjectContext is a concrete representation of your data model. Each context maintains its own state (for example, context), so changes in one context will not directly affect other contexts. When you work with multiple contexts, you are responsible for reconciling them by merging changes when the context saves its changes to the repository.
Your question is about this process and may also include merge conflicts. Whenever you save a context, its changes are committed to the repository, and the merge policy is used to resolve conflicts.
When you save the context, it will publish various progress notifications. In your case, if [contextA save:&error]
succeeds, the context will post an NSManagedObjectContextDidSaveNotification
notification. When you have multiple contexts, you usually observe this notification and call:
[contextB mergeChangesFromContextDidSaveNotification:notification]
This will merge the changes stored on contextA
into contextB
.
EDIT: deleted the comment "thread safe". NSManagedObjectContext
not thread safe.
Xjones
source share