I am unable to get NSUndoManager to function in Swift Xcode release 6.1 GM Seed 2. I've read several times the article How do I register NSUndoManager in Swift? but I can't make it work in 6.1.
Here is a code snippet showing my attempt:
func zoomFractalClick(imagePoint: NSPoint?) {
//NSLog("Point zoomed \(imagePoint)")
if imagePoint == nil { return }
let tag = zoomPopUp.selectedItem!.tag
// Try setting undo/redo
undoManager.registerUndoWithTarget(self, selector: Selector("resetFractalDef"),
object: StructWrapper<MJFractalDefinition>(object: fractalDef))
//(undoManager.prepareWithInvocationTarget(self) as AppDelegate).
// resetFractalDef(StructWrapper<MJFractalDefinition>(object: fractalDef))
fractalDef.zoomBounds(centerPoint: imagePoint!, zoomPower: Double(tag))
drawFractal()
}
func resetFractalDef( fractalDef: StructWrapper<MJFractalDefinition>) {
self.fractalDef = fractalDef.object
drawFractal()
}
class StructWrapper<T> {
let object: T
init( object: T) {
self.object = object
}
}
Using the 'simple' method, everything compiles and runs correctly even saving the Undo. However when I select Undo from the Edit menu, I get the error that it can't find the selector 'resetFractalDef'.
I've also tried the prepare with invocation method of Undo, and it fails at the point where it tries to prepare the undo with invocation target reporting 'EXC_BREAKPOINT'.
Please, any help would be appreciated. I am a Java programmer learning to program in the Apple environment mostly enjoying the using Swift.