Follow

Ok I have to be missing something here. If you add a selection binding to a List (let's say you want to edit it), then that seemingly renders all NavigationLinks in the List unusable. Surely not!?

Please someone, anyone, tell me I'm holding it wrong! gist.github.com/phillipcaudell

Well hot damn, someone on Twitter suggested setting the Set's underlying type to Optional, and voila, editing and navigation!

I'm still not entirely sure why this works though. Surely an empty Set would denote no selection? Making the type itself Optional isn't intuitive at all.

Even the init signature doesn't give any hints, only that the Binding itself can be Optional... 🤷‍♂️

@phill Sadly I gave up on using List because of gotchas like this and such limited control over how navigable list rows are rendered. I’ve since had to roll my own List-like containers and reimplement selection and deletion functionality that List gives us for free.

@phill It took work to build my own custom containers instead of using List (though really not that much work) but what I gained was predictable behaviours that don’t break with each new point release of iOS. It’s a shame that List is so buggy given lists have always been the most common UI metaphor on iOS.

@phill Try using the contextMenu:primaryAction: modifier. Primary action still gets triggered IIRC and you can set the selection manually

@brandonhorst thanks for the suggestion, though it looks updating the selection that way won't trigger the SplitView/Stack to notice any changes.

@phill Ah sorry, I replied before looking at the gist - yeah I don’t have any way around this :(

@phill Question: what happens if the Set itself is optional?
Set<Int>?

Sign in to participate in the conversation
The Not So Big Company

The home of The Not So Big Company on Mastodon.