How it works
SearchSuggestionsPlacement describes where the system may present the search suggestions you supply for a searchable view. A search field can show its suggestions in more than one location—inline within the content as the person types, or in a dedicated menu—and this type names those locations so you can control them independently. Reach for SearchSuggestionsPlacement when you want to enable, hide, or scope suggestions to a particular surface rather than letting every suggestion appear everywhere a search field can show them.
Pass a placement to the suggestions modifier
The placement-aware overload of
searchSuggestions(_:for:)takes a visibility and a set of placements, telling SwiftUI where suggestions are allowed to appear. The placement argument is a value of typeSearchSuggestionsPlacement, so this modifier is the entry point through which the symbol does its work.Target the inline content surface with .content
SearchSuggestionsPlacementexposes named placements as static members;.contentrefers to suggestions shown inline alongside the searchable content. In the example,.searchSuggestions(.hidden, for: .content)selects that surface and pairs it with a visibility so the suggestions don't display in line with theList.Combine it with a visibility to show or hide
The
for:placement says where, and the leading visibility argument says whether—here.hiddensuppresses suggestions in the chosen location. Swapping.hiddenfor.visiblere-enables them at that placement, lettingSearchSuggestionsPlacementact as a precise on/off switch per surface.Provide the suggestions it positions
Placement only governs suggestions that exist, so you still supply them with the closure form of
searchSuggestions. TheText("Apricot").searchCompletion("Apricot")andText("Blueberry").searchCompletion("Blueberry")entries are the content thatSearchSuggestionsPlacementthen routes to—or withholds from—each location.Anchor everything to a searchable field
These placement decisions apply to the field created by
searchable(text:)on the enclosingNavigationStack.SearchSuggestionsPlacementhas no effect without that search field; it simply refines where the field's suggestions surface as the boundquerychanges.
.searchSuggestions(.hidden, for: .content) to .searchSuggestions(.visible, for: .content) and watch the Apricot and Blueberry suggestions appear inline with the fruit list as you type.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 SearchSuggestionsPlacementDemo: View {
@State private var query = ""
var body: some View {
NavigationStack {
List {
Text("Apples")
Text("Bananas")
Text("Cherries")
}
.navigationTitle("Fruit")
.searchable(text: $query)
.searchSuggestions {
Text("Apricot").searchCompletion("Apricot")
Text("Blueberry").searchCompletion("Blueberry")
}
.searchSuggestions(.hidden, for: .content)
}
.padding()
}
}