searchCompletion
Associates a search token with the value of this view when used as a search suggestion.
View ModifieriOS 16.0+macOS 13.0+
Overloads
2 ways to call compose().searchCompletion(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().searchCompletion<T>(token: T)nonisolated func searchCompletion<T>(
_ token: T
) -> some View
where T : IdentifiableParameters
token*TData to use as the view’s completion.
Discussion
Use this method to associate a search token with a view that is within a search suggestion list context. The system uses this value when the view is selected to replace the partial text being currently edited of the associated search field.
enum FruitToken: Hashable, Identifiable, CaseIterable {
case apple
case pear
case banana
var id: Self { self }
}
@State private var text = ""
@State private var tokens: [FruitToken] = []
SearchPlaceholderView()
.searchable(text: $text, tokens: $tokens) { token in
switch token {
case .apple: Text("Apple")
case .pear: Text("Pear")
case .banana: Text("Banana")
}
}
.searchSuggestions {
Text("🍎").searchCompletion(FruitToken.apple)
Text("🍐").searchCompletion(FruitToken.pear)
Text("🍌").searchCompletion(FruitToken.banana)
}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.