Thursday, January 26, 2023

SwiftUI Views Are Lists

Chris Eidhof (Mastodon):

When you write SwiftUI, all your views conform to the View protocol. The name of this protocol is a bit misleading: it could be called Views or ViewList, or something else that suggests plurals.

[…]

As mentioned, the Layout protocol lets you work with these view lists directly as of iOS 16 and macOS 13. You can also use variadic views — a non-public, but stable API — to loop over view lists. The variadic view API is really powerful (for example, you can write things like filter, map and reduce on view lists) but also quite low-level. I have a gist here with some examples, and plan to also write this up soon.

Previously:

Update (2023-01-27): Chris Eidhof:

To deal with these lists of views (e.g. during layout) we can use the underscored variadic view API.

Comments RSS · Twitter · Mastodon

Leave a Comment