Method names :: add = insertObject?


Hey All,
I must be missing something.

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” button to the NSArrayController 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. What’s going on behind the scenes?


It’s does not call - (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index;.
It calls the NSArrayControllers add: method, which was linked in chapter 8. This method knows how to add an object to the mutable array.
Take a look at it’s documentation.

In this chapter we connect the Add Employee button to the File’s Owner method createEmployee.

  • (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index; is KVC for the NSMutableArray *employees Array and not the NSArrayController.

Personally I wish Cowboy dude would show the same application using KVC and old school techniques separately.
He tends to mash it up.

I’m still a noob so if I make an error… :blush: