If you replace the call to undo.prepare(withInvocationTarget: Any) with
undo.registerUndo(withTarget: self) { this in
this.removeObjectFromEmployeesAtIndex(index)
}
the undo call works. However, the NSArrayController ( and thus the NSTableView) is not observing whatever mechanism it used to observe to be made aware of this call. Therefore, the Table View does not update to reflect the fact that you just undid your add employee.
Edit:
You wouldn’t use the above method, you’d use:
undo.registerUndo(withTarget: self) { this in
this.arrayController.removeObject(employee)
}
and similar for the remove function.