SwiftUI Views Are Lists
When you write SwiftUI, all your views conform to the
View
protocol. The name of this protocol is a bit misleading: it could be calledViews
orViewList
, 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 likefilter
,map
andreduce
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.