Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created November 20, 2021 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/4b4f4898f7fc59a5aa91e4c8691afbd6 to your computer and use it in GitHub Desktop.
Save laevandus/4b4f4898f7fc59a5aa91e4c8691afbd6 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@StateObject var viewModel = ViewModel()
enum FormEntry: Hashable {
case lastName, firstName, email
}
@FocusState var focused: FormEntry?
var body: some View {
VStack {
Text("Application")
TextField("Last Name", text: $viewModel.lastName, prompt: nil)
.focused($focused, equals: .lastName)
TextField("First Name", text: $viewModel.firstName, prompt: nil)
.focused($focused, equals: .firstName)
TextField("Email", text: $viewModel.email, prompt: nil)
.focused($focused, equals: .email)
Button("Reset") {
viewModel.reset()
focused = .lastName
}
}
.frame(idealWidth: 600)
.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment