NSManagedObjectContext: undo save-operation?

core-data, ios5, nsundomanager

Solution

Could you use a child managed object context to do your save (which pushes it up to the parent, but doesn't touch the file on disk), and then do a rollback on the parent if you want to undo it?

I think calling `save` is like committing all the changes you've made since the last save, and `rollback` is like discarding them. Once you've committed the changes, they're in the persistent store and there's nothing keeping transaction logs in order to support rolling back.

Can you explain a bit more about why you want a `save` in the middle of your transaction?

Problem

I'd like to undo a save-operation on my NSManagedObjectContext; I always thought, that's what the NSUndoManager is for, but it seems as if undoing over a save-operation doesn't work... An example: ``` [[NSManagedObjectContext MR_contextForCurrentThread] setUndoManager:[NSUndoManager new]]; [[NSManagedObjectContext MR_contextForCurrentThread].undoManager beginUndoGrouping]; MyDataObject *mdo = [MyDataObject MR_createInContext:[NSManagedObjectContext MR_contextForCurrentThread]]; mdo.name = @"..."; [[NSManagedObjectContext MR_contextForCurrentThread] save:nil]; [[NSManagedObjectContext MR_contextForCurrentThread].undoManager endUndoGrouping]; [[NSManagedObjectContext MR_contextForCurrentThread].undoManager undo]; ``` But the insertion is not undone... is there no way to achieve this? Like a transaction?

Original source