Add keyboard shortcut for Search

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:

  1. 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)
        }
    }
}
Add keyboard shortcut for Search
 
 
Q