I am trying to make a year selector, with information that comes from an array, but whenever I select an option the selector always returns automatically to the first position, how could I save the selected year in my $ i.anio?
//---------------MODEL----------------- struct SysNoAntpatologicosModel { var anio: Int var descripcion: String var idantnopat: Int var nombre: String var presente: Bool } //-------------ARRAY---------------- [{ anio = 2001; descripcion = "test1"; idantnopat = 38; nombre = Accidente; presente = 0; }, { anio = 2002; descripcion = "test2"; idantnopat = 42; nombre = Inmunizacion; presente = 0; } ] @State var dataSys : [SysNoAntpatologicosModel] = [] ForEach($dataSys, id: \.idantnopat) { $i in HStack{ Picker("", selection: $i.anio) { ForEach(2000...2021, id: \.self) { Text($0) } } .pickerStyle(InlinePickerStyle()) .onChange(of: i.anio) { tag in print("year: \(tag)") } } } 