On macOS, how do you place a toolbar item on the trailing edge of the window's toolbar when an Inspector view is open?

Using SwiftUI on macOS, how can I add a toolbar item on the right-most (trailing) edge of the window's toolbar when an Inspector is used?

At the moment, the toolbar items are all left-of (leading) the split view tracking separator. I want the inspector toolbar item to be placed similar to where Xcode's Inspector toolbar item is placed: always as far right (trailing) as possible.

    NavigationSplitView {
      // ... snip
    } detail: {
      // ... snip
    }
    .inspector(isPresented: $isInspectorPresented) {
      InspectorContentView()
    }
    .toolbar {
      // What is the correct placement value here?
      ToolbarItem(placement: .primaryAction) {
        Button {
          isInspectorPresented.toggle()
        } label: {
          Label("Toggle Inspector", systemImage: "sidebar.trailing")
        }
      }
    }

See the attached screenshot. When the InspectorView is toggled open, the toolbar item tracks leading the split view tracking separator, which is not consistent with how Xcode works.

Turns out if you accidentally move the toolbar from being on the NavigationSplitView to being on the InspectorContentView then you get the behaviour I was looking for.

.inspector(isPresented: $isInspectorPresented) {
  InspectorContentView()
    .toolbar {
      ToolbarItem {
        Spacer()
      }
      ToolbarItem(placement: .primaryAction) {
        Button {
          isInspectorPresented.toggle()
        } label: {
          Label("Toggle Inspector", systemImage: "sidebar.right")
        }
      }
    }
}

If you found the solution, please accept your own reply as the correct answer. That'll show others that your post has an answer, and will help them when they come across your post when searching. Thanks!

Your orignal implementation works as expected on macOS Tahoe 26 Beta 4. Could you please test on the beta as well.

var body: some View {
    NavigationSplitView {
        sidebar
    } detail: {
        detailContent
    }
    .inspector(isPresented: $isInspectorPresented) {
        InspectorContentView()
    }
    .toolbar {
        ToolbarItemGroup(placement: .primaryAction) {
            ...
        }
    }
}
	

macOS Tahoe 26 Beta 4 does, somewhat, fix the problem but it also introduces a new set of problems. Namely:

  • The Sidebar icon is now trailing-aligned instead of leading align, which means the Sidebar icon now moves as the sidebar is toggled.
  • The tracking separator for the inspector view is now ignored. Toolbar items that are leading of the separator under Sequoia are now flush-trailing with the Inspector toolbar item on Tahoe.

See the attached screenshots comparing the two. The Sequoia screenshot was compiled under Xcode 16 running on Sequois. The Tahoe screenshot was compiled under Xcode 26b4 running on Tahoe.

In both cases the Minimum Deployment is set to macOS 15.5.

Note the difference in positions between the toolbar items. The toolbar code is the "original" implementation, whereby .toolbar and all ToolbarItems are attached to the NavigationSplitView.

On macOS, how do you place a toolbar item on the trailing edge of the window's toolbar when an Inspector view is open?
 
 
Q