I want to produce a list of input TextFields with a ForEach loop. The textFields are obviously @State variables.
I do get the error:
Generic struct 'ForEach' requires that 'Binding' conform to 'Hashable'
Here is my code:
struct ContentView: View {
@State private var mainPrice = ""
@State private var mainGrade = ""
var body: some View {
var inputFields = [$mainPrice,$mainGrade]
HStack {
List{
ForEach(inputFields, id: \.self) { value in /// here is the error
TextField("Enter data", text: value)
}
}
}
}
So, I am putting the binding variables in an array since I need a binding type in the loop, maybe that is not how to do this? I tried to add Hashable to the inputFields var to respond to the error message, but I am suspecting the whole setup is wrong.