Requires that 'FormFields' conform to 'FocusStateCompliant'
denis-obukhov opened this issue · 1 comments
denis-obukhov commented
What's wrong with this code?
enum FormFields {
case firstName, lastName, email, password
}
struct SignUpView: View {
@FocusStateLegacy var focusedField: FormFields?
@State var firstName = ""
var body: some View {
TextField(
"First name",
text: $firstName
)
.focusedLegacy($focusedField, equals: .firstName)
}
}
The issue is "Instance method 'focusedLegacy(_:equals:)' requires that 'FormFields' conform to 'FocusStateCompliant'"
denis-obukhov commented
Sorry, I forgot about the extension:
extension FormFields: FocusStateCompliant {
static var last: FormFields {
.firstName
}
var next: FormFields? {
switch self {
case .firstName:
return .lastName
case .lastName:
return .email
case .email:
return .password
default: return nil
}
}
}