Overloads
2 ways to call compose().searchSuggestions(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().searchSuggestions(suggestions: ReactNode)nonisolated func searchSuggestions<S>(
@ContentBuilder _ suggestions: () -> S
) -> some View
where S : ViewParameters
suggestions*ReactNodeA content builder that produces content that populates a list of suggestions.
Discussion
You can suggest search terms during a search operation by providing a
collection of view to this modifier. The interface presents the
suggestion views as a list of choices when someone activates the
search interface. Associate a string with each suggestion
view by adding the View.searchCompletion(_:) modifier to
the view. For example, you can suggest fruit types by displaying their
emoji, and provide the corresponding search string as a search
completion in each case:
ProductList()
.searchable(text: $text)
.searchSuggestions {
Text("🍎").searchCompletion("apple")
Text("🍐").searchCompletion("pear")
Text("🍌").searchCompletion("banana")
}When someone chooses a suggestion, SwiftUI replaces the text in the search field with the search completion string. If you omit the search completion modifier for a particular suggestion view, SwiftUI displays the suggestion, but the suggestion view doesn't react to taps or clicks.
of type Text, like in the above example. Other platforms can use any
view for the suggestions, including custom views.
You can update the suggestions that you provide as conditions change.
For example, you can specify an array of suggestions that you store in a model:
ProductList()
.searchable(text: $text)
.searchSuggestions {
ForEach(model.suggestedSearches) { suggestion in
Label(suggestion.title, image: suggestion.image)
.searchCompletion(suggestion.text)
}
}If the model's suggestedSearches begins as an empty array, the
interface doesn't display any suggestions to start. You can then provide
logic that updates the array based on some condition. For example, you
might update the completions based on the current search text. Note that
certain events or actions, like when someone moves a macOS window, might
dismiss the suggestion view.
For more information about using search modifiers, see doc:Adding-a-search-interface-to-your-app.
See also
More in Navigation.
- assistiveAccessNavigationIconConfigures the view's icon for purposes of navigation.
- asyncImageURLSessionA modifier that adds a URL session for asynchronous images contained in the view to use when fetching image data.
- contentToolbarPopulates the toolbar of the specified content view type with the views you provide.
- defaultAdaptableTabBarPlacementSpecifies the default placement for the tabs in a tab view using the adaptable sidebar style.
- defaultTabBarPlacementSpecifies the preferred placement for the tabs of a TabView in the TabViewStyle.sidebarAdaptable style on platforms where the tab bar cannot adapt between different representations, and only one representation can be shown.
- navigationBarBackButtonHiddenHides the navigation bar back button for the view.
- navigationBarTitleDisplayModeConfigures the title display mode for this view.
- navigationDestinationAssociates a destination view with a presented data type for use within a navigation stack.
- navigationDocumentConfigures the view's document for purposes of navigation.
- navigationLinkIndicatorVisibilityConfigures whether navigation links show a disclosure indicator.
- navigationSplitViewColumnWidthSets a fixed, preferred width for the column containing this view.
- navigationSubtitleConfigures the view's subtitle for purposes of navigation, using a localized string resource.