Copy pending changes between NSManagedObjectContexts with persistent persistent storage?

I have two instances NSManagedObjectContext: one is used in the main thread, and the other is used in the background thread (via NSOperation.) For thread safety, these two contexts are used only NSPersistentStoreCoordinator.

The problem I encountered is pending changes in the first context (in the main thread), which are not available in the second context until executed -save. This is understandable, because in the general store with persistent storage will not be stored up NSManagedObjects, monitored -insertedObjects, -updatedObjectsand -deletedObjects.

Unfortunately, this creates a problem with the user interface: any unsaved changes will not be displayed in reports (time) that are generated in the background thread.

The only solution I can think of is unpleasant: take the inserted, updated, and deleted objects from the first context and transfer them to the object graph of the second context. The data set has a rather complicated relationship, so I hesitate to go in that direction. I hope someone here will be a better solution.

+5
source share
4 answers

10.7, : ManagedObjectContexts, "" , , , .

10.7 , , . , NSManagedObjectContextObjectsDidChangeNotification, . ( 20 .) , ?

+4

, - , iOS 5/Mac OS 10.7 . , , .

: , , , iOS 5/Mac OS 10.7 NSManagedObjectContextDidSaveNotification userInfo // .

+2

.

0

, . "" API- . , .

​​ ...

And that would be a stable solution. I come from a database-driven world (oracle), we often use such patterns (state attributes in records) to make data visible / invisible to other database sessions (which will be equal to the flows in the cocoa application). It always works without problems. Other threads / sessions always see only registered changes that show how most RDBMSs work.

0
source

All Articles