I have two instances of NSManagedObjectContext
: one is used in main thread and the other is used in a background thread (via an NSOperation
.) For thread safety, these two contexts only share an NSPersistentStoreCoordinator
.
The problem I'm having is with pending changes in the first context (on the main thread) not being available to the second context until a -save
is performed. This is understandable since the shared persistent store won't have copies of the NSManagedObjects
being tracked by -insertedObjects
, -updatedObjects
, and -deletedObjects
are persisted.
Unfortunately, this presents a problem with the user experience: any unsaved changes won't appear in the (time consuming) reports that are generated in the background thread.
The only solution I can think of is nasty: take the inserted, updated and deleted objects from the first context and graft them onto the object graph of the second context. There are some pretty complex relations in the dataset, so I'm hesitant to go in this direction. I'm hoping someone here as a better solution.