I going through Cocoa Programming for OS X book by Big Nerd Ranch, and I'm stuck on Chapter 11 -- working with NSUndoManager. As I understand, NSUndoManager is now just UndoManager, but I can't get the rest of the sample code to compile.
The relevant code is:
class Document: NSDocument {
@objc dynamic var employees: [Employee] = []
func insertObject(employee: Employee, inEmployeesAtIndex index: Int) {
let undo: UndoManager = undoManager!
undo.prepare(withInvocationTarget: self).insertObjectFromEmployeesAtIndex(employees.count)
if !undo.isUndoing {
undo.setActionName("Add Person")
}
}
func insertObjectFromEmployeesAtIndex(index: Int) {
let employee: Employee = employees[index]
let undo: UndoManager = undoManager!
undo.prepare(withInvocationTarget: self).insertObject(employee: employee, inEmployeesAtIndex: index)
employees.remove(at: index)
}
}
The error I get is for lines undo.prepare
in both functions. The error is:
Value of type 'Any' has no member 'insertObjectFromEmployeesAtIndex'
and
Cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members