Instance Property インスタンスプロパティ

isSearching

A Boolean value that indicates when the user is searching.

Declaration 宣言

var isSearching: Bool { get }

Discussion 議論

You can read this value like any of the other EnvironmentValues, by creating a property with the Environment property wrapper:


@Environment(\.isSearching) private var isSearching

Get the value to find out when the user interacts with a search field that’s produced by one of the searchable modifiers, like searchable(text:placement:prompt:):


struct SearchingExample: View {
    @State private var text = ""


    var body: some View {
        NavigationView {
            SearchedView()
                .searchable(text: $text)
        }
    }
}


struct SearchedView: View {
    @Environment(\.isSearching) private var isSearching


    var body: some View {
        Text(isSearching ? "Searching!" : "Not searching.")
    }
}

When the user first taps or clicks in a search field, the isSearching property becomes true. When the user cancels the search operation, the property becomes false. To programmatically set the value to false and dismiss the search operation, use dismissSearch.

See Also 参照

State 状態