Search code examples
objective-ccocoacocoa-bindings

Aaron Hillegass :: [NSArrayController add] = insertObject method


I must be missing something. I'm in the chapter titled "Key-Value Observing" in Cocoa Programming by Aaron Hillegass.

I have inserted the code that enables the application to undo/redo adding and subtracting employees from RaiseMan. The application works however what I'm wondering is why is that when I link the "Add Employee" to the NSArrayController to the ADD method (using the .xib file) it calls

- (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index;

According to the Key-Value Coding, shouldn't the add method call?

- (void)addEmployeesObject:newEmployee;

I'm linking the 'add' method not the 'insert' method.


Solution

  • Your array controller is bound to an ordered collection (an array). That's why it uses insertObject:inEmployeesAtIndex: to add a new object at the end of the the collection.

    The addEmployeesObject: method would be used if the collection was unordered (i.e. a set).