NSUndoManager casting NSUndoManagerProxy crash in Swift code

前端 未结 2 1733
借酒劲吻你
借酒劲吻你 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: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)
    

提交回复
热议问题