I want to use the newly presented ability to focus on something in SwiftUI, in my case a TextField where the user should input something:
struct MyView: View {
@State var name: String = ""
@FocusState private var nameIsFocused: Bool
var body: some View {
Form {
TextField("Name", text: $name).focused($nameIsFocused)
}
.onAppear {
nameIsFocused = true
}
}
}
For some reason this is not working. Any Idea why? I don't get the focus when entering the view.