SwiftUI: how to add toolbar to a window for a macOS app?

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()

// Toolbar **needs** a delegate
NSToolbar.taskListToolbar.delegate = self
// Create the window and set the content view.
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false)
// Assign the toolbar to the window object
window.toolbar = .taskListToolbar
window.titleVisibility = .hidden
window.setFrameAutosaveName("Main Window")
window.contentView = NSHostingView(rootView: contentView)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store



Indie developer on everything Apple — macOS, iOS, watchOS, etc. I build great apps: Sched, Eventbrite, Eventbrite Organizer (Neon). Ping me for projects.