title: Is it OK to use multiple NSUndoManagers with one Core-Data managedObjectContext?
body: <p>//Edit: Really, nobody has any suggestions or thoughts on this?  Have I asked the question wrongly somehow?//</p>
  
  <p>My iPhone app has a single managedObjectContext with a moderately complicated data model.  I'm now adding undo functionality, and am not clear on how best to handle nested viewControllers (as each layer might modify the data model).  </p>
  
  <blockquote>
    <p>Apple's docs point out:
    "Consider an application that displays
    a list of books, and allows you to
    navigate to a detail view that in turn
    allows you to edit individual
    properties of the book (such as its
    title, author, and copyright date).
    You might create a new book from the
    list screen, navigate between two
    other screens to edit its properties,
    then navigate back to the original
    list. It might seem peculiar if an
    undo operation in the list view undid
    a change to the author’s name that was
    made two screens away rather than
    deleting the entire book."</p>
  </blockquote>
  
  <hr>
  
  <p>So what's the best way to implement this? Currently, I'm thinking to have each viewController keep its own undoManager, which would be active whenever it's on the screen. So my understanding is that this would require the following steps (for each VC):</p>
  
  <ul>
  <li>Add a property:        <code>myUndoManager</code> </li>
  <li>Add an <code>undoManager</code> method returning <code>myManagedObjectContext.undoManager;</code></li>
  <li>In <code>viewDidAppear</code>:    <code>myManagedObjectContext.undoManager = myUndoManager;</code> //create first if nil</li>
  <li>In <code>viewWillDisappear</code>: <code>myManagedObjectContext.undoManager = nil;</code></li>
  <li>On memory warning:     <code>[self.undoManager removeAllActions ];</code></li>
  <li>On dealloc:             <code>self.myUndoManager = nil;</code></li>
  <li>For each model change: <code>[self.undoManager setActionName:NSLocalizedString(@“XXX”,@“”)];</code></li>
  <li>CoreData will handle the actual undo/redo postings</li>
  </ul>
  
  <p>In addition, I have to remain firstResponder:</p>
  
  <ul>
  <li>In <code>viewDidAppear</code>: `[self becomeFirstResponder]'</li>
  <li>Add <code>canBecomeFirstResponder</code> method returning YES</li>
  <li>In <code>viewWillDisappear</code>: [self resignFirstResponder];</li>
  <li>Re-enable firstResponder upon subViews resign (e.g. textFields)</li>
  </ul>
  
  <p>So far, that seems like it works, even across load/unload cycles, and is nicely self-contained, but I have several questions:</p>
  
  <ul>
  <li>First, is this the best practice for implementing undo across multiple VCs?</li>
  <li>Will I get in trouble with my child VCs not doing their undos prior to my doing my earlier ones?</li>
  <li>If so, does that list capture everything I need to do?</li>
  <li>Will ManagedObjectContext get confused with multiple UndoManagers being active?</li>
  <li>Do I need to call ProcessPendingActions before swapping undoManagers?</li>
  </ul>