I tried to create a very simple TextField in SwiftUI but I cannot get it to work and I don't understand what I am doing wrong.
Xcode gives me an error message that says:
"Unable to infer complex closure return type; add explicit type to disambiguate."
I am not sure what to do. I found some other code examples for TextFields with SwiftUI on StackOverflow but keep getting the same error.
struct TextFieldExample : View {
@State var email: String = "Enter email address"
var body: some View {
VStack {
TextField($email)
Text("Your email is \(email)!")
}
}
}
struct ButtonTextField : View {
@State var text: String = ""
var body: some View {
HStack {
TextField($text,
placeholder: Text("type something here..."))
Button(action: {
// Closure will be called once user taps your button
print(self.$text)
}) {
Text("SEND")
}
}
}
}
Expected results = working TextField Actual result = Error in Xcode
TextFieldstruct? You're effectively redeclaring SwiftUI's nativeTextField.