Fill the blank
Fill the blank so Next moves focus to the password field.
enum Field { case email, password }
@FocusState private var focus: Field?
TextField("Email", text: $email)
.focused($focus, equals: .email)
SecureField("Password", text: $password)
.focused($focus, equals: .password)
Button("Next") { ____ }Hint 1 of 1
Focus state is a value you assign.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A focus = .password
Correct. Assigning the focus state moves keyboard focus.
Why not the others?
- B
focus.toggle(). An optional enum can't be toggled. - C
$focus = .password.$focusis a binding projection; you assign the wrapped value. - D
passwordField.becomeFirstResponder(). That's UIKit; SwiftUI has no view reference to call.