ENHANCEMENT: Core Data, NSOperation and NSUndoManager are incompatible

Originator:craig.hockenberry
Number:rdar://8977725 Date Originated:
Status:Open Resolved:
Product:Mac OS X Product Version:10.6.6
Classification:Enhancement Reproducible:Always
 
I'm working on some code that uses an NSOperation to import data. I'd like for the user to be able to undo the NSManagedObject instances that are created during the import operation.

From what I can tell, it's impossible to use the NSManagedObjectContext -undoManager for any operations that are performed off of the main thread. From the "Core Data Programming Guide" section on "Use Thread Confinement to Support Concurrency", we have these two conditions:

1. Only objectID should be passed between managed object contexts (on separate threads)
2. Managed objects must be saved in a context before the objectID can be used.

This makes sense since the managed objects need to be moved from private storage (NSManagedObjectContext) to public storage (NSPersistentStore) before they can be shared.

Unfortunately, the -save: message also causes any managed objects in the undo stack to be removed. From the "Memory Management Using Core Data" section of the same guide:

"Managed objects that have pending changes (insertions, deletions, or updates) are retained by their context until their context is sent a save:, reset , rollback, or dealloc message, or the appropriate number of undos to undo the change."

I've tried several things to work around this limitation, and everything eventually leads back to bulk of the work happening on the main thread (and spinning beach balls.)

Ideally, there should be a way to move the contents of -insertedObjects, -deletedObjects and -updatedObjects from one NSManagedObjectContext to another (across threads.) The current mechanism of relying on saved data in the persistent store results in implementations that are not as user friendly as they could be (no undo.)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!