I am migrating a Mac OS X Xode 7 / Swift 2.2 project to Xcode 8 / Swift 3 and I am having a problem using undoManager in my controller class MyViewController, which has a cancel function.
On Xcode 7 / Swift 2.2, this worked fine:
undoManager?.prepareWithInvocationTarget(self).undo(data, moreData: moreData) undoManager?.setActionName("Change Data)
In Xcode 8 / Swift 3, using the recommended template from https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html
this should be changed to:
if let target = undoManager?.prepare(withInvocationTarget: self) as? MyViewController { target.undo(data, moreData: moreData) undoManager?. setActionName("Change Data") }
However, the downcast for MyViewController always fails, and the undo operation is not registered.
Am I missing something obvious here, or is this a mistake?
source share