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.