.searchScopes modifier not adding scope bar to search

I’m unable to use the .searchScopes modifier to add a segmented Picker to my search bar as of developer beta 6. It will not display whether I’m using a NavigationStack, NavigationSplitView, or NavigationView. Has anyone had any luck using this modifier?

This simple code will demonstrate the problem.

struct ContentView: View {

    @State var searchText: String = ""
    @State var searchScope: String = "Scope 1"

   
    let data = Array(0..<20)

    var body: some View {

        NavigationStack {

            List {

                ForEach(data, id:\.self) { item in

                   Text("\(item)")

                }

            }

            .searchable(text: $searchText)
            .searchScopes($searchScope, scopes: {

                    Text("Scope 1")
                    Text("Scope 2")

            })

        }

    }

}

I've submitted this as FB11298015

Post not yet marked as solved Up vote post of talkingsmall Down vote post of talkingsmall
1.2k views

Replies

The search scopes are there, but there seems to be a bug where you have to start typing for it to appear.

I started seeing this bug in beta 2 of iOS 16. I remember it actually worked in the first beta but broke in beta 2 and has been broken ever since. I wrote a feedback ticket back then on it as well (FB10516559). And yes, once you start typing the scope bar shows up. This is an unacceptable UX though as the user should see all the scopes and be able to change them as soon as the search bar is tapped, not after the first character is typed. It's also jarring to the user to have the scope bar animate during typing.

As of iOS 16.4, you can say:

    .searchScopes($searchScope, activation: .onSearchPresentation, {
      Text("Scope 1")
      Text("Scope 2")
    })

to force the search-scopes Picker to appear as soon as search bar is tapped.