Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

NSToolbar doesn't restore displayMode when NSWindow.titleVisibility = .hidden

Apparently when setting a window to hide its title, the toolbar's displayMode is not restored when relaunching the app. For example, by default my app sets to show toolbar icons only, but when right-clicking it, selecting "Icon and Text" and relaunching the app, it's again "Icon Only".

Is there a workaround? I've filed FB17144212.

class ViewController: NSViewController, NSToolbarDelegate {

    override func viewDidAppear() {
        let toolbar = NSToolbar(identifier: "toolbar")
        toolbar.delegate = self
        toolbar.autosavesConfiguration = true
        toolbar.displayMode = .iconOnly
        view.window?.titleVisibility = .hidden
        view.window?.toolbar = toolbar
        view.window?.toolbarStyle = .unified
    }
    
    func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        return [.init(rawValue: "item")]
    }
    
    func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
        return [.init(rawValue: "item")]
    }
    
    func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
        let item = NSToolbarItem(itemIdentifier: itemIdentifier)
        item.image = NSImage(named: NSImage.addTemplateName)!
        item.label = "item"
        return item
    }

}

Thanks for filling the bug report. The engineering teams is investigating this issue and would let you know via the Feedback report if there's a supported workaround

NSToolbar doesn't restore displayMode when NSWindow.titleVisibility = .hidden
 
 
Q