Ancestors

Toot

Written by Rhys Morgan on 2024-11-02 at 17:38

omg, just discovered a new API that seems to have been added (and backported!) in SwiftUI for setting the tag of a view for situations like a tabItem or Picker when the Binding type is Optional, and you're ForEach-ing over non-Optional values.

Instead of having to remember the magick invocation of:

Text(flavour.rawValue).tag(Optional.some(flavour))

you can now just use:

Text(flavour.rawValue).tag(flavour)

https://developer.apple.com/documentation/swiftui/view/tag(_:includeoptional:)/

[#]iosdev #swiftlang #swiftui

=> More informations about this toot | More toots from rhysmorgan@mastodon.social

Descendants

Written by Rhys Morgan on 2024-11-02 at 17:42

This change seems to have happened without anyone calling it out? It's a massive improvement to SwiftUI, because the problem was pretty much impenetrable. You just had to know that your tag type needed to match – including optionality, which goes against most other cases in Swift. Now, you get correct behaviour by default!

[#]iosdev #swiftlang #swiftui

=> More informations about this toot | More toots from rhysmorgan@mastodon.social

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

This content has been proxied by September (3851b).