TechnologiesSwiftUISearch and Find

SearchSuggestionsPlacement struct

iOSmacOStvOSwatchOSvisionOSiOS 16.0+✓ renders

The ways that SwiftUI displays search suggestions.

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.

  1. 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 type SearchSuggestionsPlacement, so this modifier is the entry point through which the symbol does its work.

  2. Target the inline content surface with .content

    SearchSuggestionsPlacement exposes named placements as static members; .content refers 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 the List.

  3. Combine it with a visibility to show or hide

    The for: placement says where, and the leading visibility argument says whether—here .hidden suppresses suggestions in the chosen location. Swapping .hidden for .visible re-enables them at that placement, letting SearchSuggestionsPlacement act as a precise on/off switch per surface.

  4. Provide the suggestions it positions

    Placement only governs suggestions that exist, so you still supply them with the closure form of searchSuggestions. The Text("Apricot").searchCompletion("Apricot") and Text("Blueberry").searchCompletion("Blueberry") entries are the content that SearchSuggestionsPlacement then routes to—or withholds from—each location.

  5. Anchor everything to a searchable field

    These placement decisions apply to the field created by searchable(text:) on the enclosing NavigationStack. SearchSuggestionsPlacement has no effect without that search field; it simply refines where the field's suggestions surface as the bound query changes.

Try it — Change .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.

SearchSuggestionsPlacement.swift
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()
    }
}
Live preview
Search Apples Bananas Cherries 9:41 Fruit
Search Apples Bananas Cherries 9:41 Fruit
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →