I'm trying to create a stack of poker chips in SwiftUI. I've got a ChipView which is a view of a single chip. I'm now trying to layer ChipViews in a stack to create of poker chips. I'm having trouble building a for loop following the rules of a view builder.
I want to do the following:
ZStack {
for index in 0..<chipCount {
ChipView()
.offset( CGSize(width: index * 5, height: index * 5))
}
}
But I know that I can't do that in a view builder. I know I should use ForEach
but can't think of how. I could build an array of indexes to use ForEach(indexArray) { index in ... }
but that seems very clunky and unsatisfying.
I feel like this is trivially easy but I couldn't a solution from googling.