{"id":38644,"date":"2023-03-01T15:45:43","date_gmt":"2023-03-01T20:45:43","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=38644"},"modified":"2023-03-01T15:45:43","modified_gmt":"2023-03-01T20:45:43","slug":"swiftui-views-versus-modifiers","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/03\/01\/swiftui-views-versus-modifiers\/","title":{"rendered":"SwiftUI Views Versus Modifiers"},"content":{"rendered":"<p><a href=\"https:\/\/swiftbysundell.com\/articles\/swiftui-views-versus-modifiers\/\">John Sundell<\/a>:<\/p>\n<blockquote cite=\"https:\/\/swiftbysundell.com\/articles\/swiftui-views-versus-modifiers\/\">\n<p>So, regardless of whether we want to change the styles or structure of a view, or introduce a new piece of state, it&rsquo;s starting to become clear that SwiftUI views and modifiers have the exact same capabilities. But that brings us to the next question &mdash; if there are no practical differences between the two approaches, how do we choose between them?<\/p>\n<p>At least to me, it all comes down to the <em>structure<\/em> of the resulting view hierarchy.<\/p>\n<p>[&#8230;]<\/p>\n<p>Looking at the view-based call site above, it&rsquo;s very clear that our two texts are being wrapped within a container, and it&rsquo;s also easy to tell which of those two texts will end up being the leading versus trailing view.<\/p><p>That same thing can&rsquo;t really be said for the modifier-based version this time, though, which really requires us to know that the view that we&rsquo;re <em>applying<\/em> the modifier to will end up in the leading slot. Plus, we can&rsquo;t really tell that those two texts will end up being wrapped in some kind of container at all. It looks more like we&rsquo;re styling the leading label using the trailing label somehow, which really isn&rsquo;t the case.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>John Sundell: So, regardless of whether we want to change the styles or structure of a view, or introduce a new piece of state, it&rsquo;s starting to become clear that SwiftUI views and modifiers have the exact same capabilities. But that brings us to the next question &mdash; if there are no practical differences between [&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-03-01T20:45:46Z","apple_news_api_id":"329b4eba-27d8-42c2-8952-6dad08188aa7","apple_news_api_modified_at":"2023-03-01T20:45:46Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AMptOuifYQsKJUm2tCBiKpw","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,1812],"class_list":["post-38644","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-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38644","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=38644"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38644\/revisions"}],"predecessor-version":[{"id":38645,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/38644\/revisions\/38645"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=38644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=38644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=38644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}