It's blowing up inside the onChange handler and I just didn't quite figure out what it needed. Will start earlier in the day tomorrow and look at that.
I know I've solved this kind of problem before, just don't remember precisely how.
@deirdresm@bwebster in my one example (cellArrayTest) if I could just force the entire grid to redraw when the dropdown change that would seem to solve the core existing issue.
@bynkii@deirdresm Can you bind the selection of the picker directly to theGame.gridSize instead of using the other @State gridSize var as a go between? I think onChange() would go away then too.
You could then add a didSet on the Game.gridSize var, and trigger the rebuild of the cell array there.
class Game {
var gridSize: Int {
didSet {
self.gridCellArr = buildStructArray(theGridSize: gridSize)
}
}
}
I'll try it, but not convinced that would fix it, and here's why: It re-drawing UI mid-onChange handler means that the onChange handler itself isn't running on the main thread. (I realized that last night, but had a migraine, so….)
So it may also need to be specifically run on the main thread.
@deirdresm@bwebster I took a deeper look and yeah, it’s wild. As soon as I change the index size in the picker, the index changes to the new higher value, and it looks like it modifies the label value before the array can be rebuilt with the new index and as it’s trying to use index = 15 on a 9-member array.
At least that’s what it looks like to me, and I’m probably wrong.
Add comment