ForEach(questionsManager.answerChoices, id:\.id) { answer in
AnswerRow(index: i, answer: answer).environmentObject(questionsManager)
}
"i" is a @State variable in my View Struct that is assigned to zero
I want the index of each AnswerRow to be set from 0 to 3, how to manage that?
>Solution :
Rather than the elements iterate the indices of the array
ForEach(questionsManager.answerChoices.indices, id: \.self) { i in
AnswerRow(index: i, answer: questionsManager.answerChoices[i]).environmentObject(questionsManager)
}
The @State variable is actually not needed.
Side note: As you pass the questionsManager in the environment the answer parameter is not needed either.