This is an OS X app ; using Swift 2.2 in XCode 7.3.
I have a windowController with a view aView
I am trying to implement undoin a func, but the undoManager remains nil.
func changeColor(sender: NSMenuItem) {
undoManager?.registerUndoWithTarget(self, selector: #selector(remove(_:)), object: aView) //
undoManager?.setActionName("colored")
Swift.print(undoManager) // always get nil
}
The function for undo / redo :
func add(v: NSView) {
undoManager?.registerUndoWithTarget(self, selector: #selector(remove(_:)), object: v) /
}
func removeCircle(v: NSView) {
undoManager?.prepareWithInvocationTarget(self).add(v) /
}
I have declared the view as firstResponder in windowDidLoad
self.aView.becomeFirstResponder()
In changeColor, undoManager remains nil.
Where should I initialize it ?