I'm trying to make a view with some pickers. The selections should be connected to a property of an binding array:
@Binding var limits: [Limit]
var body: some View {
ForEach(limits) { limit in
HStack {
Text("Value \(limit.value): "
Text("\(limit.from, specifier: "%.1f")")
Text(" - ")
let values = getChangeValuesByLimit(limit: limit)
Picker("lower", selection: ????) {
ForEach(values, id:\.self) { value in
Text("\(value, specifier: "%.1f")").tag(value)
}
}
}
}
}
I don't know how to save the selection (????). How can I achieve this?
limitsdoesn't need to be a Binding. Instead, pass the limits array as a constant that you can use for looping (let limits: [Limit]), and accept a@Binding var selectedLimit: Limit?as a second parameter that you can use in your picker:Picker("lower", selection: $selectedLimit).