NSArrayController insert vs add


I have a question about setting the target of the Add Employee button to the array controller (on page 137)
I set it to “add:” as specified. And then, on page 152, in dealing with the undo codes, it was mentioned that the add Employees
and Remove buttons would call the “insert:” and “remove:” messages.

So I looked and realized there are both “add:” and “insert:” actions that may be received by the NSArrayController.
I changed to the “insert:” but both seemed to work fine.

Are there any differences?



I am not quite sure because I am a newbie, but I guess the add: messages refers to the addObject: message of an array, means the new object is added as the last element of the array. The insert: message then will refer to the insertObject:atIndex: method of an array, means that the object is added at a specific index, here the row number, not at the end. Try to check by adding a new employee while having one selected in your tableView. If the new one appears at the end, you should have used add:, if it appears above your selected employee, you hopefully used insert:.


… and you are absolutely correct !



Yeah! Progress!