I have a macOS Application with a NavigationView
and want to have the default ToggleSidebar item in the toolbar of the window.
Currently I set the target of the ToolbarItem to the AppDelegate in toolbarWillAddItem(_)
of the NSToolbarDelegate
.
Inside of the AppDelegate I implemented
@objc func toggleSidebar(_ sender: Any) {
((window.contentView?.subviews.first?.subviews.first?.subviews.first as? NSSplitView)?.delegate as? NSSplitViewController)?.toggleSidebar(self)
}
This solution is working right now. If the implementation of SwiftUI will change this breaks.
So how can this be done in a better way?