I have an app that runs perfectly on macOS 14 & 15. But I would like to support macOS 13 too. But on macOS 13 the toolbar doesn't show the title and the button.
The code below is showing my mixed AppKit/SwiftUI approach. In my real app I need some more control on window management. That's why I didn't migrate to the SwiftUI App approach yet.
@main class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow?
func applicationDidFinishLaunching(_ notification: Notification) {
let view = SideBar()
let contentView = NSHostingView(rootView: view)
let window = NSWindow(
contentRect: NSRect(origin: .zero, size: CGSize(width: 500, height: 400)),
styleMask: [.titled, .unifiedTitleAndToolbar, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered,
defer: false
)
window.contentView = contentView
window.toolbar = NSToolbar()
window.center()
window.makeKeyAndOrderFront(nil)
self.window = window
}
}
struct SideBar: View {
var body: some View {
NavigationView {
NavigationLink(destination: ContentView()) {
Text("Content")
}
}
}
}
struct ContentView: View {
var body: some View {
HStack {
Spacer()
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
Spacer()
}
.padding()
.navigationTitle("Test")
.toolbar {
ToolbarItem(placement: .automatic) {
Button {
} label: {
Label("Add", systemImage: "plus")
}
}
}
}
}
macOS 15 (Expected)
macOS 13 (Missing toolbar title and button)