I'm creating an NSViewRepresentable
view to use an NSView
in a SwiftUI code.
And I need the NSViewRepresentable
code to customize app's main menu via NSApp.mainMenu
property.
But turns out the the eligible AppKit code for the task is not working in SwiftUI environment. By debugging the main menu I see that the items I add to the menu appears in the NSMenu instance but those items aren't showing in SwiftUI app menu, yet they show up in AppKit app menu.
Debugging shows that in SwiftUI environment the app's main menu uses SwiftUI.AppKitMainMenuItem
object instead of NSMenuItem
. But it is an Apple's private class I can not use.
How to achieve that in SwiftUI environment? I really need this to be done using Cocoa code base in my NSViewRepresentable class because I'm developing a universal extension for AppKit, UIKit and SwiftUI.