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?
Accepted Reply
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.
-
Other error: Cannot find ‘$calculated’ and ‘$calculator’
-
Normal, I changed to have first letter as lowercase (calculator vs Calculator, calculated vs Calculated). So, you need to change it everywhere in code.
-
I changed the first letter to lowercase, but it still show ‘didn’t find $calculator in scope’
Replies
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.
-
Other error: Cannot find ‘$calculated’ and ‘$calculator’
-
Normal, I changed to have first letter as lowercase (calculator vs Calculator, calculated vs Calculated). So, you need to change it everywhere in code.
-
I changed the first letter to lowercase, but it still show ‘didn’t find $calculator in scope’
-
—
Bringker
Add a CommentI expect Apple will answer this question in Chinese.