Post

Replies

Boosts

Views

Activity

Trying to include SwiftUI Shortcut recorder in my storyboard App
Hello, complete noob here..... is there an easy way to include SwiftUI code into a Storyboard (View Controller) Window for MacOS? I tried subclassing the NSHostingController like so: class HostingViewController: NSHostingController<MyView> { required init?(coder: NSCoder) { super.init(coder: coder,rootView: MyView()); } override func viewDidLoad() { super.viewDidLoad() } } with 'MyView' being the SwiftUI file that I want to appear in the window. I'm unable to call this window from my AppDelegate ( i.e. when the user clicks on the 'Set Shortcut' menu item): let menu = NSMenu() menu.addItem(NSMenuItem(title: "Set Shortcut", action: #selector(AppDelegate.Shortcut(sender:)), keyEquivalent: "" )) statusItem.menu = menu } @objc func Shortcut(sender: NSMenuItem){ //call the HostingViewController here } Have tried various bits of code unsuccessfullly to call the window at the point where the code is commented. Much obliged for any assistance.
1
0
381
Feb ’22