<!--
{
  "availability" : [
    "iOS: 16.4.0 -",
    "iPadOS: 16.4.0 -",
    "macCatalyst: 16.4.0 -",
    "macOS: 13.3.0 -",
    "tvOS: 16.4.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/searchScopes(_:activation:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12searchScopes_10activation_QrAA7BindingVyqd__G_AA21SearchScopeActivationVqd_0_yXEtSHRd__AaBRd_0_r0_lF"
  },
  "title" : "searchScopes(_:activation:_:)"
}
-->

# searchScopes(_:activation:_:)

Configures the search scopes for this view with the specified
activation strategy.

```
nonisolated func searchScopes<V, S>(_ scope: Binding<V>, activation: SearchScopeActivation, @ContentBuilder _ scopes: () -> S) -> some View where V : Hashable, S : View
```

## Parameters

`scope`

The active scope of the search field.

`activation`

The activation style of the search field’s scopes.

`scopes`

A content builder that represents the scoping options
SwiftUI uses to populate a [`Picker`](/documentation/SwiftUI/Picker).

## Discussion

To enable people to narrow the scope of their searches, you can
create a type that represents the possible scopes, and then create a
state variable to hold the current selection. For example, you can
scope the product search to just fruits or just vegetables:

```
enum ProductScope {
    case fruit
    case vegetable
}

@State private var scope: ProductScope = .fruit
```

Provide a binding to the scope, as well as a view that represents each
scope:

```
ProductList()
    .searchable(text: $text, tokens: $tokens) { token in
        switch token {
        case .apple: Text("Apple")
        case .pear: Text("Pear")
        case .banana: Text("Banana")
        }
    }
    .searchScopes($scope) {
        Text("Fruit").tag(ProductScope.fruit)
        Text("Vegetable").tag(ProductScope.vegetable)
    }
```

SwiftUI uses this binding and view to add a [`Picker`](/documentation/SwiftUI/Picker) below the search
field. In iOS, macOS, and tvOS, the picker appears below the search
field when search is active. To ensure that the picker operates
correctly, match the type of the scope binding with the type of each
view’s tag. Then condition your search on the current value of the
`scope` state property.

By default, the appearance of scopes varies by platform:

- In iOS and iPadOS, search scopes appear when someone enters text
  into the search field and disappear when someone cancels the search.
- In macOS, search scopes appear when SwiftUI presents search and
  disappear when someone cancels the search.

However, you can use the `activation` parameter with a value of
[`onTextEntry`](/documentation/SwiftUI/SearchScopeActivation/onTextEntry) or
[`onSearchPresentation`](/documentation/SwiftUI/SearchScopeActivation/onSearchPresentation) to configure this
behavior:

```
.searchScopes($scope, activation: .onSearchPresentation) {
    Text("Fruit").tag(ProductScope.fruit)
    Text("Vegetable").tag(ProductScope.vegetable)
}
```

For more information about using searchable modifiers, see
[Adding a search interface to your app](/documentation/SwiftUI/Adding-a-search-interface-to-your-app).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)