Skip to content

Instantly share code, notes, and snippets.

Created November 20, 2021 07:10
What would you like to do?
struct ContentView: View {
@StateObject var viewModel = ViewModel()
enum FormEntry: Hashable {
case lastName, firstName, email
@FocusState var focused: FormEntry?
var body: some View {
VStack {
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: $, prompt: nil)
.focused($focused, equals: .email)
Button("Reset") {
focused = .lastName
.frame(idealWidth: 600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment