0

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.

Community
  • 1
  • 1
  • try `selector: Selector("resetFractalDef:")` – Bryan Chen Oct 16 '14 at 00:00
  • Thanks for the suggestion to use a colon to close out the method name. But the undo still did not work. What I needed to do in addition was to use a parameter type that was a class descended from NSObject. I upgraded my MJFractalDefinition from a struct to a class descended from NSObject. Now it works. Thanks. – John E. Miller Oct 25 '14 at 03:17

0 Answers0