I want to import text from TextField(SwiftUI) in float format but I just have this error, the message said “Can’t turn the number of type ‘float’ to a unexpected type ‘Binding’”, if I try to run it will also send me the same error, how do I fix it?
How to fix this TextField to variable error?
I expect Apple will answer this question in Chinese.
You need to change to
$Calculated
and
$Calculator
But Float is not a text. So you should call
TextField("Calculated number", value: $Calculated, format: .number)
and
TextField("Calculator", value: $Calculator, format: .number)
But doing so, labels will not show.
This works better:
HStack {Text("Calculated number"); TextField("", value: $calculated, format: .number) }
and
HStack {Text("Calculator"); TextField("", value: $calculator, format: .number) }
Note also that var names should start with lowercase: calculated and calculator.