Search code examples
swiftswiftuimacos-sequoia

Duplicate item in NSToolbar error in MacOS 15


Using .searchable() on NavigationSplitView causes following error after upgrade to MacOS 15:

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

The app started failing after MacOS upgrade, upgrading to XCode 16 and rebuilding did not make it any better.

Found also described here (https://forums.developer.apple.com/forums/thread/763829), however without any hint how to fix this.


Solution

  • To fix this, I moved the .searchable() modifier from NavigationSplitView to another view like this (simplified):

    NavigationSplitView {
        Sidebar
    } content: {
        ContentView
        .searchable(text: $searchTerm) // moved here
    } detail: {
        DetailView
    }
    //.searchable(text: $searchTerm) // original placement