angadveer
OP
Created
Replies
2
Boosts
1
Views
660
Participants
3
That's just an extra view with a segmented control In it. You can put the view between the search bar at the top, and the tableview below. If you want to hide it, set the height to 0.
This is actually a feature that comes with searching called search scopes.
In SwiftUI, you would combine the searchable(text:placement:prompt:) modifier with searchScopes(_:scopes:) to achieve this effect.
Here's an example of how you would use it:
@State private var searchText = ""
@State private var selectedScope = "Option 1"
let allScopes = ["Option 1", "Option 2", "Option 3"]
...
.searchable(text: $searchText, prompt: "Search for something")
.searchScopes($selectedScope) {
ForEach(allScopes, id: \.self) { scope in
Text(scope)
}
}
Check out the documentation for each modifier, and I would highly recommend reading this article for more on searching in SwiftUI.