I have a grid view that has two columns, one that is static that will be populated with names, and the second that is user inputed numbers. I have two arrays, one full of the names, and one that is initialized to 0s for all numbers. I have it displayed as:
ScrollView{
let lastRowIndex: Int = viewModel.names.count - 1
LazyVGrid(columns: columns, alignment: .center, spacing: 0){
Group {
Text("Name")
Text("Number")
}.font(.headline)
ForEach((0...lastRowIndex), id: \.self) { index in
Text(viewModel.names[index])
TextField("indiv value", value: $viewModel.individualValues[index], format: .number)
}
}.padding(.horizontal)
}
This displays perfectly to start, two columns, one with every name in the array and one initialized to 0. But when I try to make any change to the number, as soon as I click off of the input it returns to 0. How do I set this up so that the numbers are saved in the individualValues array, displayed properly, and able to be used later?