NSUndoManager casting NSUndoManagerProxy crash in Swift code

前端 未结 2 1714
借酒劲吻你
借酒劲吻你 2021-01-06 06:04

In our application we\'re using the following code:

let lInvocationTarget = lUndoManager.prepare(withInvocationTarget: self)
let _ = (lInvocationTarget as! M         


        
相关标签:
2条回答
  • 2021-01-06 06:33

    I found registerUndoWithTarget:handler: is a better API now.

    0 讨论(0)
  • 2021-01-06 06:34

    I am so much astonished that I hear your first code works on macOS 10.12. The method prepare(withInvocationTarget:) has been a this-hardly-works-in-Swift thing. Not only the returned proxy object is not the instance of the original class, but neither the object is not a descendent of NSObject (at lease in some former OS Xs).

    Anyway, this is one thing worth trying:

    let lInvocationTarget = lUndoManager.prepare(withInvocationTarget: self)
    _ = (lInvocationTarget as AnyObject).myMethod(self.opacity, undoManager: lUndoManager)
    
    0 讨论(0)
提交回复
热议问题