SearchSuggestionsPlacement
The ways that SwiftUI displays search suggestions.
Declaration
type SearchSuggestionsPlacement = SwiftOpaque<'SearchSuggestionsPlacement'>;struct SearchSuggestionsPlacementOverview
You can influence which modes SwiftUI displays search suggestions for by
using the View.searchSuggestions(_:for:) modifier:
enum FruitSuggestion: String, Identifiable {
case apple, banana, orange
var id: Self { self }
}
@State private var text = ""
@State private var suggestions: [FruitSuggestion] = []
var body: some View {
MainContent()
.searchable(text: $text) {
ForEach(suggestions) { suggestion in
Text(suggestion.rawValue)
.searchCompletion(suggestion.rawValue)
}
.searchSuggestions(.hidden, for: .content)
}
}In the above example, SwiftUI only displays search suggestions in a suggestions menu. You might want to do this when you want to render search suggestions in a container, like inline with your own set of search results.
You can get the current search suggestion placement by querying the
EnvironmentValues.searchSuggestionsPlacement environment value in your
search suggestions.
From Apple’s SwiftUI documentation. Code samples there are Swift.
See also
More in Navigation.
- AdaptableTabBarPlacementA placement for tabs in a tab view using the adaptable sidebar style.
- AutomaticNavigationTransitionA style that automatically chooses the appropriate presentation transition for the current context.
- ContentToolbarPlacementA region of the interface that hosts its own toolbar content.
- CrossFadeNavigationTransitionA navigation transition that cross-fades between the appearing view and the disappearing view.
- DismissSearchActionAn action that can end a search interaction.
- NavigationBarItemTitleDisplayModeA style for displaying the title of a navigation bar.
- NavigationPathA type-erased list of data representing the content of a navigation stack.
- NavigationPathChainNavigationPath with chained calls: SwiftUI.NavigationPath.append(...).
- NavigationPathCodableRepresentationA serializable representation of a navigation path.
- NavigationSplitViewColumnA view that represents a column in a navigation split view.
- NavigationSplitViewVisibilityThe visibility of the leading columns in a navigation split view.
- NavigationTransitionA type that defines the transition to use when navigating to a view.