How it works
ToolbarDefaultItemKind names the toolbar items that SwiftUI inserts on your behalf — controls like the sidebar toggle, the search field, and the navigation title that a container view adds automatically based on its context. Because these items are created by the framework rather than declared in your toolbar content, you need a way to refer to one of them when you want to opt out. ToolbarDefaultItemKind is that identifier: you pass a value of this type to the toolbar(removing:) modifier to suppress a default item you don't want. Reach for it when a system-provided control conflicts with your own layout or simply isn't wanted in a particular scene.
Refer to a default item by its kind
Each system-supplied control has a corresponding
ToolbarDefaultItemKindvalue exposed as a type property, so you select one with leading-dot syntax instead of constructing it yourself. In the example,.sidebarToggleidentifies the automatic sidebar-toggle button that SwiftUI would otherwise place in the toolbar.Remove it with toolbar(removing:)
The
toolbar(removing:)modifier takes aToolbarDefaultItemKindand tells SwiftUI to leave that default item out of the rendered toolbar. Here.toolbar(removing: .sidebarToggle)strips the sidebar toggle while leaving the rest of the toolbar — and every item you declare explicitly — untouched.Apply it where the default items live
Default toolbar items are generated by the surrounding navigation container, so the modifier belongs on a view inside that container. In the example it sits on the
Listwithin aNavigationStack, the same place wherenavigationTitle("Pieces")andsearchable(text: $query)register their own toolbar contributions.Compose with other automatic items
Removing one kind doesn't disturb the others, which lets a default control coexist with content the framework adds elsewhere. The
searchable(text:)modifier still contributes its search field even though the.sidebarTogglekind has been removed, because each default item is addressed independently by its ownToolbarDefaultItemKind.
.toolbar(removing: .sidebarToggle) line and the sidebar-toggle button reappears in the toolbar, showing exactly which default item that ToolbarDefaultItemKind value controls.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct ToolbarDefaultItemKindDemo: View {
@State private var query = ""
var body: some View {
NavigationStack {
List {
Text("Bishop")
Text("Knight")
Text("Rook")
}
.navigationTitle("Pieces")
.searchable(text: $query)
.toolbar(removing: .sidebarToggle)
}
.padding()
}
}