I have one array that I want to iterate over and make a button object for each element of the array. However, I want to have two VStacks that split these buttons up, essentially two columns with many rows of the text objects, but I want it to go from left to right in sequential order. In one column would be the odd numbers (or even indexes i.e. 3rd number is index 2), in the second column would be the even numbers (or odd indexes). Here is my code as of right now, but it doesn't split them up it just makes duplicates.
HStack{
VStack{
ForEach(game.ButtonAnswers, id: \.id){ answer in
ButtonRows(answer: answer)
.environmentObject(game)
}
}
VStack{
ForEach(game.ButtonAnswers, id: \.id){ answer in
ButtonRows(answer: answer)
.environmentObject(game)
}
}
}
From left to right reading across the VStacks, my code gives 1, 1, 2, 2, 3, 3, etc. I want it to be 1, 2, 3, 4, 5, 6, etc. so that one VStack contains, 1, 3, 5 the other 2, 4, 6
Let me know if you have any suggestions on how to do this. Thank you!