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.