Overview
- I have a SwiftUI list with a search field
- I would like to add a keyboard shortcut for search field to be in focus
Questions:
- How can I add a keyboard shortcut for search field?
import SwiftUI
struct ContentView: View {
@State private var searchText = ""
var body: some View {
NavigationStack {
List(0..<100) { index in
Text("Cell \(index)")
}
.searchable(text: $searchText)
}
}
}