I have just started learning SwiftUI and got stuck somewhere!
I am trying to change segment styled picker datasource when changing value of another segment. But some
Nick Polychronakis solved it in this fork: https://github.com/nickpolychronakis/100DaysOfSwiftUI/tree/master/UnitCoverter
The solution is to add .id(:identifier:) to your picker so it is unique.
Observable var:
@State var unit = 0
Main picker:
Picker("Length", selection: $unit) {
ForEach(0 ..< inputUnitTypes.count) {
Text("\(self.inputUnitTypes[$0].description)")
}
}
.pickerStyle(SegmentedPickerStyle())
One of secondary pickers which content is determined by the unit variable.
Picker("Length", selection: $inputUnit) {
ForEach(0 ..< selected.count) {
Text("\(self.selected[$0].description)")
}
}
.id(unit)