{"id":38289,"date":"2023-01-26T15:44:06","date_gmt":"2023-01-26T20:44:06","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=38289"},"modified":"2023-01-27T14:47:45","modified_gmt":"2023-01-27T19:47:45","slug":"swiftui-views-are-lists","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/01\/26\/swiftui-views-are-lists\/","title":{"rendered":"SwiftUI Views Are Lists"},"content":{"rendered":"<p><a href=\"https:\/\/chris.eidhof.nl\/post\/swiftui-views-are-lists\/\">Chris Eidhof<\/a> (<a href=\"https:\/\/m.objc.io\/@chris\/109751198846392579\">Mastodon<\/a>):<\/p>\n<blockquote cite=\"https:\/\/chris.eidhof.nl\/post\/swiftui-views-are-lists\/\"><p>When you write SwiftUI, all your views conform to the <code>View<\/code> protocol. The name of this protocol is a bit misleading: it could be called <code>Views<\/code> or <code>ViewList<\/code>, or something else that suggests plurals.<\/p><p>[&#8230;]<\/p><p>As mentioned, the <code>Layout<\/code> protocol lets you work with these view lists directly as of iOS 16 and macOS 13. You can also use <a href=\"https:\/\/movingparts.io\/variadic-views-in-swiftui\">variadic views<\/a> &mdash; a non-public, but stable API &mdash; to loop over view lists. The variadic view API is really powerful (for example, you can write things like <code>filter<\/code>, <code>map<\/code> and <code>reduce<\/code> on view lists) but also quite low-level. I have a gist <a href=\"https:\/\/gist.github.com\/chriseidhof\/5ff6ef8786f5635c18b20304ab9d9b01\">here<\/a> with some examples, and plan to also write this up soon.<\/p><\/blockquote>\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/06\/17\/swiftui-changes-at-wwdc-2022\/\">SwiftUI Changes at WWDC 2022<\/a><\/li>\n<\/ul>\n\n<p id=\"swiftui-views-are-lists-update-2023-01-27\">Update (2023-01-27): <a href=\"https:\/\/chris.eidhof.nl\/post\/variadic-views\/\">Chris Eidhof<\/a>:<\/p>\n<blockquote cite=\"https:\/\/chris.eidhof.nl\/post\/variadic-views\/\">\n<p>To deal with these lists of views (e.g. during layout) we can use the underscored variadic view API.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>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.[&#8230;]As mentioned, the Layout protocol lets you work with these view lists directly as of iOS 16 and macOS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2023-01-26T20:44:14Z","apple_news_api_id":"9da21727-5dcc-4763-9800-72feea256210","apple_news_api_modified_at":"2023-01-27T19:47:50Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AnaIXJ13MR2OYAHL-6iViEA","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,2185,30,2223,71,901,1812],"class_list":["post-38289","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-16","tag-mac","tag-macos-13-ventura","tag-programming","tag-swift-programming-language","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=38289"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38289\/revisions"}],"predecessor-version":[{"id":38297,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38289\/revisions\/38297"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=38289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=38289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=38289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}