我正在阅读Big Nerd Ranch撰写的Cocoa Programming for OS X书籍,我坚持使用第11章-使用NSUndoManager。据我了解,NSUndoManager现在只是UndoManager,但是我无法编译其余示例代码。
相关代码为:
Foo
我得到的错误是两个函数中的第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)
}
}
行。错误是:
undo.prepare
和
Value of type 'Any' has no member 'insertObjectFromEmployeesAtIndex'