Challenge - SPOILERS

The first challenge is straightforward, but can be tricky. Add a for loop to iterate over the selected employees and be sure to set the value, not the property to zero:

        case NSAlertSecondButtonReturn:
                println("Keep, but no raise selected")
                for employee in selectedPeople {
                    employee.setValue(0.0, forKey:"raise")
                    // wrong:
                    //employee.raise = 0.0
                }

The second challenge is simple, but there’s a catch…

let message: String let infoText: String if selectedPeople.count > 1 { message = "Do you really want to remove these people?" infoText = "\(selectedPeople.count) people will be removed." } else { message = "Do you really want to remove this person?" let employee:Employee! = selectedPeople.first if let name = employee.name as String? { infoText = "\(name) will be removed." } else { infoText = "1 person will be removed." } }

Notice the check to make sure there is a string. Without this, it would crash if the employee had no name.

The following code works for for the Keep challenge:

        [code]case NSAlertThirdButtonReturn:
            for employee in selectedPeople {
                employee.raise = 0.0
            }
            // re-sort (in case the user has sorted a column)
            self.arrayController.rearrangeObjects()[/code]

Without the last line, nothing appears to change. The last line triggers redrawing of the table view, showing that the values have changed.

BTW, replacing the last line with

does not show the values changed; would anyone like to elaborate?

Hi tombernard…the issue with your code is that by setting the value directly, via:

will not fire off the Key-Value Observing and thus the Array Controller and the Table View won’t update.

If you use:

Then all the updates will happen.

lol, I made the second challenge while I was typing the source code :slight_smile:

For the first challenge I chose this way:

case NSAlertThirdButtonReturn: for employee in selectedPople { employee.raise = 0 } self.tableView.reloadData()