How it works
DefaultToolbarItem lets you place one of SwiftUI's system-provided toolbar controls into a toolbar by referring to it by kind, rather than building the control yourself. Some standard affordances — most notably search — are normally positioned and managed by the framework, and a DefaultToolbarItem gives you a handle to that built-in item so you can decide where it appears. Reach for it inside a toolbar builder when you want to relocate or explicitly position a system item, such as moving the search field down to the bottom bar.
Add it inside a toolbar builder
DefaultToolbarItemis aToolbarContentvalue, so you list it in the closure passed to the.toolbarmodifier just like aToolbarItem. In the example it sits alongside theListwithin aNavigationStack, declared as the sole entry of.toolbar { DefaultToolbarItem(...) }.Choose the system item with the kind parameter
The
kindparameter names which framework-provided item you're referring to. Here it's.search, which identifies the search field that the.searchable(text:)modifier contributes —DefaultToolbarItemdoesn't create a new search field, it represents that existing one.Position it with the placement parameter
The
placementparameter takes aToolbarItemPlacementand decides where the item is shown. The example passes.bottomBar, which pulls the search affordance out of its default location and pins it to the bottom toolbar.Pair it with the feature that supplies the item
Because
DefaultToolbarItempoints at a system item rather than defining one, the corresponding feature must be present for it to resolve. The.searchkind only has something to place because.searchable(text: .constant(""))is applied to the sameList.
placement: argument from .bottomBar to .topBarTrailing and watch the search field move from the bottom toolbar up beside the "Inbox" navigation title.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 DefaultToolbarItemDemo: View {
var body: some View {
NavigationStack {
List {
Text("Mail")
Text("Calendar")
Text("Notes")
}
.navigationTitle("Inbox")
.searchable(text: .constant(""))
.toolbar {
DefaultToolbarItem(kind: .search, placement: .bottomBar)
}
}
}
}