- (void)cancel {
// [managedObjectContext.undoManager disableUndoRegistration];
[managedObjectContext deleteObject:object]; // I don't want this deletion to be recorded on the undo stack which is empty at this point.
// [managedObjectContext.undoManager enableUndoRegistration];
[managedObjectContext.undoManager removeAllActions];
}
With this code, I still got the deletion on the undo stack, even uncommenting those two lines can not prevent the recording. Why?
You’ll need to call -processPendingChanges on the managed object context before disabling and before re-enabling undo processing. Core Data delays registering undo events until processPendingChanges to allow for coalescing multiple changes to the same attribute and similar shortcuts.