SwiftUI toolbar in MacOS 15 bug ?

struct ContentView: View {
    var body: some View {
        NavigationSplitView {
            List {
                Text("row 1")
                Text("row 2")
                Text("row 3")
            }
            .toolbar(content: {
                ToolbarItem {
                    Button("aa", action: onToolbar)
                }
            })
        } detail: {
            HSplitView {
                
                VStack {
                    Image(systemName: "globe")
                        .imageScale(.large)
                        .foregroundStyle(.tint)
                    Text("Hello, world!")
                }
                .toolbar(id: "toolbar", content: {
                    ToolbarItem(id: "toolbar-1") {
                        Button("bb", action: onToolbar)
                    }
                })
                .padding()
                
                Text("right")
            }
        }.navigationTitle("")
    }
    
    
    func onToolbar() {}
}

Run & Crash

NSToolbar 0x6000005665b0 already contains an item with the identifier com.apple.SwiftUI.splitViewSeparator-0. Duplicate items of this type are not allowed.

@snaill Please file a bug report using Feedback Assistant and post the Feedback number here for the record.

Secondly, could you provide some context on what you're trying to achieve and why you have a ToolbarItem within the sidebar? Thanks

Same problem.

I plan to implement an interface similar to Xcode, with several tool buttons on the sidebar and several tool buttons on the main interface. The main interface embeds a SplitView, which has two views on the left and right. The tool buttons should change with the switching of the left view. In MacOS14, there is no problem with the code. When it is updated to 15, there is a problem.

NSToolbar 0x6000005665b0 already contains an item with the identifier com.apple.SwiftUI.splitViewSeparator-0. Duplicate items of this type are not allowed.

In addition, I found that if I don't use SplitView, there will be no problem. I tried setting the id of the ToolbuttonItem, but it didn't work.

Same problem.

struct ContentView: View {
    var body: some View {
        NavigationSplitView {
            List {
                Text("row 1")
                Text("row 2")
                Text("row 3")
            }
        } detail: {
            HSplitView {
                
                VStack {
                    Image(systemName: "globe")
                        .imageScale(.large)
                        .foregroundStyle(.tint)
                    Text("Hello, world!")
                }
                .toolbar(id: "toolbar", content: {
                    ToolbarItem {
                        Button("bb", action: onToolbar)
                    }
                    ToolbarItem {
                        Button("cc", action: onToolbar)
                    }
                })
                .padding()
                
                Text("right")
            }
        }.navigationTitle("")
    }
    
    
    func onToolbar() {}
}

FAULT: NSInternalInconsistencyException: NSToolbar 0x600001f10f30 already contains an item with the identifier com.apple.SwiftUI.splitViewSeparator-0. Duplicate items of this type are not allowed.; { NSAssertFile = "NSToolbar.m"; NSAssertLine = 1609; }

Same, but with the searchbar:

"Thread 1: "NSToolbar 0x6000001c74e0 already contains an item with the identifier com.apple.SwiftUI.search. Duplicate items of this type are not allowed.""

This started as soon as I updates to Xcode Version 16.0

The "offending" code:

NavigationSplitView {
...
}
.searchable(
            text: $searchText,
            placement: .automatic,
            prompt: "Search..."
 )

I got the same and I don't use a search bar. My app can switch between tab control or Navigation Split View and I debug by putting a toggle. Up until now I've used the NavigationSplitView for my Mac version but I saw the tabview update and decided to try it and my app crashed when pressing a tab and gave me no good warning.

Creating a simple tabview to NavigationSplitView sample code I get the same, with this mentioned error, when tapping a tabview option. Code:

struct ContentView: View {
    @State var isCompact: Bool = false

    var body: some View {
        VStack {
            if isCompact {
                EntryTab()
            }  else {
                EntrySidebar()
            }
            Toggle(isOn: $isCompact, label: {
                Text(isCompact ? "On" : "Off")
            })
            .padding(.horizontal, 20)
            .padding(.bottom, 20)
        }
    }
}

public struct tabControl: Identifiable, Hashable, Sendable {
    public static func == (lhs: tabControl, rhs: tabControl) -> Bool {
        lhs.id < rhs.id
    }
    
    public var id: Int // Tab Number
    public var displayName: String
    
    public init(id: Int, displayName: String) {
        self.id = id
        self.displayName = displayName
    }
}

struct EntryTab: View {
    let entryTabs = [
        tabControl(id: 0, displayName: "row 0"),
        tabControl(id: 1, displayName: "row 1"),
        tabControl(id: 2, displayName: "row 2"),
        tabControl(id: 3, displayName: "row 3")
    ]
    @State private var selectedTab: Int = 0
    
    var body: some View {
        TabView(selection: $selectedTab) {
            ForEach(entryTabs) { tabCtrl in
                NavigationSplitView {
                    Text("Selected tab is \(selectedTab)")
                } detail: {
                    Text("Choose item from sidebar... in future this would be content")
                }
                .tabItem {
                    Text(tabCtrl.displayName)
                }
                .tag(tabCtrl.id)
            }
        }
    }
}

struct EntrySidebar: View {
    @State private var selectedTabID: Int?
    let entryTabs = [
        tabControl(id: 0, displayName: "row 0"),
        tabControl(id: 1, displayName: "row 1"),
        tabControl(id: 2, displayName: "row 2"),
        tabControl(id: 3, displayName: "row 3")
    ]
    
    var body: some View {
        NavigationSplitView(sidebar: {
            List(entryTabs, id:\.id, selection: $selectedTabID) { thisItem in
                Text(thisItem.displayName)
            }
        }, content: {
            Text("Hi selected tab: \(String(describing: selectedTabID))")
        }, detail: {
            Text("Choose item from sidebar... in future this would be content")
        })
        .onAppear() {
            // Set the selected tab
            selectedTabID = 1
        }
    }
}

Realized I didn't share the error: Thread 1: "NSToolbar 0x600003fa74e0 already contains an item with the identifier com.apple.SwiftUI.navigationSplitView.toggleSidebar. Duplicate items of this type are not allowed."

I have filed the issue at Stack Overflow just to make sure more eyes can see it: https://stackoverflow.com/questions/79034976/duplicate-item-in-nstoolbar-error-in-xcode-16

SwiftUI toolbar in MacOS 15 bug ?
 
 
Q