I am trying to build a dynamic Picker with a segmented style that re-renders itself based on user input.
So in other words, every time the user adds a value to the filterValues array the segmented picker should re-render.
This what I tried and not working:
struct ContentView: View {
@State private var items = [Item]()
@State private var filterValueIndex = 0
@State private var filterValues: [Int] = [1, 2, 3, 5]
var body: some View {
Picker("Filter", selection: $filterValueIndex) {
ForEach(0 ..< filterValues.count) {
Text("\(filterValues[$0])")
}
}
.pickerStyle(SegmentedPickerStyle())
}
}