title: NSUndoManager not working. Aaron Hillegass chapter 9
body: <p>I have been working through cocoa programming for Mac OS X by Aaron Hillegass.  I have become stuck on chapter 9.  I have added the 2 methods necessary to allow the undo and redo functions to be called.  However, when I build and run the application, according to the book, the methods should be automatically called, yet they are not.  They are spelt correctly as you can see below...</p>
  
  <p><strong>2 additional methods in MyDocument.m</strong></p>
  
  <pre><code>- (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index
  {
      NSLog(@"Adding %@ to %@", p, employees);
          //Add the inverse of this operation to the undo stack
      NSUndoManager *undo = [self undoManager];
      [[undo prepareWithInvocationTarget:self]removeObjectFromEmployeesAtIndex:index];
      if (![undo isUndoing]){
          [undo setActionName:@"Insert Person"];
      }
          //Add teh person to the array
      [employees insertObject:p atIndex:index];
  }
  
  - (void)removeObjectFromEmployeesAtIndex:(int)index
  {
      Person *p = [employees objectAtIndex:index];
      NSLog(@"Removing %@ to %@", p, employees);
          //Add the inverse of this operation to the undo stack
      NSUndoManager *undo = [self undoManager];
      [[undo prepareWithInvocationTarget:self]insertObject:p inEmployeesAtIndex:index];
      if (![undo isUndoing]){
          [undo setActionName:@"Delete Person"];
      }
      [employees removeObjectAtIndex:index];
  }
  </code></pre>
  
  <p><strong>myDocument.h</strong></p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  @class Person;
  
  @interface MyDocument : NSDocument
  {
      NSMutableArray *employees;
  }
  - (void)setEmployees:(NSMutableArray *)a;
  - (void)removeObjectFromEmployeesAtIndex:(int)index;
  - (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index;
  @end
  </code></pre>
  
  <p>Any help would be great, thanks :)</p>