title: NSInvocation for Dummies?
body: <p>How exactly does <code>NSInvocation</code> work? Is there a good introduction?</p>
  
  <p>I’m specifically having issues understanding how the following code (from <em>Cocoa Programming for Mac OS X, 3rd Edition</em>) works, but then also be able to apply the concepts independently of the tutorial sample. The code:</p>
  
  <pre><code>- (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index
  {
      NSLog(@"adding %@ to %@", p, employees);
      // Add inverse of this operation to undo stack
      NSUndoManager *undo = [self undoManager];
      [[undo prepareWithInvocationTarget:self] removeObjectFromEmployeesAtIndex:index];
      if (![undo isUndoing])
          [undo setActionName:@"Insert Person"];
  
      // Finally, add person to the array
      [employees insertObject:p atIndex:index];
  }
  
  - (void)removeObjectFromEmployeesAtIndex:(int)index
  {
      Person *p = [employees objectAtIndex:index];
      NSLog(@"removing %@ from %@", p, employees);
      // Add inverse of this operation to undo stack
      NSUndoManager *undo = [self undoManager];
      [[undo prepareWithInvocationTarget:self] insertObject:p
                                         inEmployeesAtIndex:index];
      if (![undo isUndoing])
          [undo setActionName:@"Delete Person"];
  
      // Finally, remove person from array
      [employees removeObjectAtIndex:index];
  }
  </code></pre>
  
  <p>I get what it’s trying to do. (BTW, <code>employees</code> is an <code>NSArray</code> of a custom <code>Person</code> class.)</p>
  
  <p>Being a .NET guy, I try to associate unfamiliar Obj-C and Cocoa concepts to roughly analogous .NET concepts. Is this similar to .NET’s delegate concept, but untyped? </p>
  
  <p>This isn’t 100% clear from the book, so I’m looking for something supplemental from real Cocoa/Obj-C experts, again with the goal that I understand the fundamental concept beneath the simple(-ish) example. I'm really looking to be able to independently apply the knowledge -- up until chapter 9, I was having no difficulty doing that. But now ...  </p>
  
  <p>Thanks in advance!</p>