How do you do the cast below, in an App with SwiftUI Lifecycle, where AppDelegate is implemented as NSApplicationDelegateAdaptor
?
let appDelegate = NSApplication.shared.delegate as! AppDelegate
// or
let appDelegate = NSApp.delegate as! AppDelegate
The above throws the following error:
Could not cast value of type 'SwiftUI.AppDelegate' (0x1e28fae40) to 'MyApp.AppDelegate' (0x102d277c0).
Background is using AppDelegate in an Extension
extension NSStatusBarButton {
public override func mouseDown(with event: NSEvent) {
super.mouseDown(with: event)
let appDelegate = NSApp.delegate as! AppDelegate
// do stuff with appDelegate on MouseDown Event
}
}