Create macOS SideBar in Swift
Last night I started digging into building a SideBar for Pra.
Sadly, I struggled to find a decent example of how to programmatically create a SideBar in Swift for macOS.
After a little bit of trial and error the following is the working solution I came up with.
import Cocoa
extension NSSplitViewController {
convenience init(sideBarViewController: NSViewController, contentViewController: NSViewController) {
self.init(nibName: nil, bundle: nil)
let sideBarSplitViewItem = NSSplitViewItem(sidebarWithViewController: sideBarViewController)
let contentSplitViewItem = NSSplitViewItem(viewController: contentViewController)
self.addSplitViewItem(sideBarSplitViewItem)
self.addSplitViewItem(contentSplitViewItem)
}
}