Connecting the Remove Button

Next, you will connect the Remove button to the remove(_:) method on the array controller. This will be much the same as connecting the Add Employee button, but there are some additional considerations, as you will see.

Control-drag from the Remove button to Array Controller and set the action to remove:.

Run the application. Add two employees and give them pleasant names. Select the first one and click Remove. Contrary to your notions of all that is good and right in the world, the second employee has been removed! Now that nothing is selected, try clicking Remove once more. Even though no rows are selected, a row will be removed! What is going on here?

The array controller’s remove(_:) method removes ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.