I'm getting this error : Picker: the selection "3" is invalid and does not have an associated tag, this will give undefined results.
Because new brand doesn't have 3 values and .onChange
modifier is not working fast enough. Thanks for your help.
Picker("Marka", selection: $brandIndex) {
Text("Seçin").tag(0)
ForEach(cars.indices, id: \.self) {
Text(cars[$0].brand).tag($0 + 1)
}
}
.onChange(of: brandIndex) {
if modelIndex != 0 {
modelIndex = 0
}
}
Picker("Model", selection: $modelIndex) {
Text("Seçin").tag(0)
if brandIndex != 0 {
let _ = print(modelIndex) // I'm getting first 3 then 0. And I'm getting error.
ForEach(cars[brandIndex - 1].models.indices, id: \.self) {
Text(cars[brandIndex - 1].models[$0])
.tag($0 + 1)
}
}
}