bynkii,
@bynkii@mastodon.social avatar

@deirdresm @bwebster Okay, so the curse of too many projects running at once, the thing where it's not updating the coordinates in all the cells when I resize is in THIS project: https://github.com/johncwelch/cellArrayTest

which has significant differences from buttonTest2 (https://github.com/johncwelch/buttonTest2)

I did make some updates to buttonTest 2 and push those up. The comments on lines 58/59 show where it's currently blowing up

soo....close.

deirdresm,
@deirdresm@hachyderm.io avatar

@bynkii @bwebster

Just realize I didn't update you.

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.

bynkii,
@bynkii@mastodon.social avatar

@deirdresm @bwebster really? That’s kind of wild

bynkii,
@bynkii@mastodon.social avatar

@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.

sigh. so close and yet…

bwebster,
@bwebster@mastodon.social avatar

@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)
}
}
}

deirdresm,
@deirdresm@hachyderm.io avatar

@bwebster @bynkii

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,
@deirdresm@hachyderm.io avatar

@bwebster @bynkii

Confirmed that it still blows up when you shrink the array, so I'll try wrapping it.

(It makes sense an onChange handler wouldn't be on the main thread because you're using it to do some processing that's not itself UI.)

bynkii,
@bynkii@mastodon.social avatar

@deirdresm @bwebster one of the Hacking With Swift folks seems to have come up with an answer!

it's all in https://github.com/johncwelch/cellArrayTest, but basically, he did what Brian suggested and added a didset for gridSize.

He then said to set the picker selection to $gameObj.gridSize and we set all the grid foreach’s to use that too.

then on the closing brace for the first foreeach loop, he added a id(gameObj.gridSize)

resizing now works, every square is redrawn and gets the correct coordinates!

bynkii,
@bynkii@mastodon.social avatar

@deirdresm @bwebster he also added a sanity check for the index to avoid out of bounds errors.

But yeah, it all seems to be working now!

deirdresm,
@deirdresm@hachyderm.io avatar

@bynkii @bwebster

Oh, wow! Glad that worked! I got busy with other things so hadn't tried further.

The thing I hadn't tried was changing all the Grid ForEach, which is where it was blowing up.

Yay, onward progress.

bynkii,
@bynkii@mastodon.social avatar

@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.

deirdresm,
@deirdresm@hachyderm.io avatar

@bynkii @bwebster You’re correct, that’s what it’s doing. I was staring at it last night and yelled at the computer, “Seriously?” 🙄

So, it’s not you.

bynkii,
@bynkii@mastodon.social avatar

@deirdresm @bwebster okay, so that’s just weird AF to me

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • mdbf
  • ethstaker
  • magazineikmin
  • GTA5RPClips
  • rosin
  • thenastyranch
  • Youngstown
  • osvaldo12
  • slotface
  • khanakhh
  • kavyap
  • InstantRegret
  • Durango
  • provamag3
  • everett
  • cisconetworking
  • Leos
  • normalnudes
  • cubers
  • modclub
  • ngwrru68w68
  • tacticalgear
  • megavids
  • anitta
  • tester
  • JUstTest
  • lostlight
  • All magazines