I am trying to find the best solution to connect a NSMenuItem with SwiftUI onCommand on macOS.
Currently I an doing the following:
I ended up creating a PassthroughSubject
in my AppDelegate, passing it through to my SwiftUI view, and subscribing to it in the model object owned by my SwiftUI view. When my AppDelegate selector for the menu command is called, I send the event using the PassthroughSubject
, which my model receives and handles appropriately.
My answer is definitely not ideal, and I'd love to know if you figure out a better way to do this.