I have a Mac app with an Appkit lifecycle. I would like to create a window that is entirely defined by SwiftUI, including the toolbar.
What I've tried:
Programmatically create an
NSWindow
and set its view to be anNSHostingView
to a SwiftUI view that uses.toolbar(...)
. The toolbar does not show up.Programmatically create an
NSWindow
and anNSToolbar
, set up the toolbar using Appkit APIs and assign the toolbar to the window. The toolbar shows up as expected, but is not configured using SwiftUI and it is awkward to have the toolbar reference or interact with SwiftUI view state.Rewrite the entire app with a SwiftUI lifecycle. Works fine. Not really an option for me.
Primary question:
Is there a way to wire up the toolbar for a manually created NSWindow
in such a way that SwiftUI views can use the .toolbar
attributes to place/manage items in it?
If the answer is simply, "no":
- Is there a way to create a full SwiftUI lifecycle window without the entire app being constructed that way? (I have many non-SwiftUI windows that can't/won't be converted)
- Alternatively, is there a way for the Appkit toolbar code to less awkwardly reference View state in SwiftUI views and/or respond to published changes in SwiftUI state?