Ancestors

Toot

Written by Ben Scheirman on 2025-01-21 at 15:10

I think my biggest gripe with SwiftUI is that it's too easy to "hold it wrong"

Fixed an issue that was troubling me for the past couple short working sessions:

presenting an editable form that takes an [@]Binding with the sheet modifier requires some binding projection shenanigans. However the set closure was causing my sheet to dismiss then reappear, then dismiss again.

After commenting out the set closure entirely it works... but why?

1/

=> More informations about this toot | More toots from bens@mastodon.xyz

Descendants

Written by Ben Scheirman on 2025-01-21 at 15:14

It's because I'm using SwiftData and the Item was a reference type. Mutating the single instance will update the source of the binding.

But it took me so long to realize I should have been using [@]Bindable instead of [@]Binding.

Doing so made the code way cleaner, I was able to remove my sheet(unwrapping:) modifier, and it all works.

But there was no indication I was doing something wrong. Just strange behavior that was hard to understand, and harder to explain.

2/2

=> More informations about this toot | More toots from bens@mastodon.xyz

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113866978358770076
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
235.720351 milliseconds
Gemini-to-HTML Time
0.409698 milliseconds

This content has been proxied by September (ba2dc).