I have one main NSManagedObjectContext
with some entities and another background NSManagedObjectContext
with same objects as the main NSManagedObjectContext
. I add some objects to the background NSManagedObjectContext
(that may exist in the main NSManagedObjectContext
) and basically what I want is to be able to join the two NSManagedObjectContext
instances thus making CRUD (create,read update and delete) on the objects from both NSManagedObjectContext
instances so they're mirrored 1:1.
Is this possible?
NSManagedObjectContext
instances are just scratch pads. They both point to the same underlying NSPersistentStoreCoordinator
. Therefore when you call -save:
in one NSManagedObjectContext
then the NSPersistentStoreCoordinator
will get updated and you can retrieve those changes into the other NSManagedObjectContext
.
If your "background" NSManagedObjectContext
is a child of your "main" NSManagedObjectContext
then just calling -save:
on the background NSManagedObjectContext
will cause the main NSManagedObjectContext
to be updated automatically. That is one of the benefits of the parent/child design.
In any case, the NSManagedObjectContext
instances are just temporary until you save. When you save, those changes all go to the same place; the NSPersistentStoreCoordinator
.