LazyVGrid(columns: columnGrid, spacing: 0) {
if model.state == .two {
ForEach(Array(model.cats.enumerated()), id: \.offset) { offset, cat in
CatView(cat: cat)
.frame(height: 50)
}
}
} else {
ForEach(Array(model.cats.enumerated()), id: \.offset) { offset, cat in
CatView(cat: cat)
.frame(height: 50)
}
}
}
}
When the model is in state "one", the else
portion of this code block is executed, and all CatViews are updated properly. However, when the model state is changed to "two, the if
portion of this executed. The ForEach
line gets hit, and a breakpoint reveals that model.cats is valid. The problem is that the CatView()
line is never executed in this case (it should be hit 10 times if there are 10 Cats for example). It's the exact same code as in the else block. What could be the reason the code inside the first ForEach
block does not get executed?