{"id":36042,"date":"2022-06-01T16:04:00","date_gmt":"2022-06-01T20:04:00","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=36042"},"modified":"2022-06-02T20:01:35","modified_gmt":"2022-06-03T00:01:35","slug":"make-your-swiftui-view-modifiers-safer","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/06\/01\/make-your-swiftui-view-modifiers-safer\/","title":{"rendered":"Safer SwiftUI View Modifiers"},"content":{"rendered":"<p><a href=\"https:\/\/blog.eidinger.info\/make-your-swiftui-view-modifiers-safer\">Marco Eidinger<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.eidinger.info\/make-your-swiftui-view-modifiers-safer\">\n<p>Despite the missing qualifier, the code compiles because <code>padding()<\/code> gets treated as <code>self.padding()<\/code>. During runtime, that leads to an infinitely recursive View =&gt; stack overflow &#x1F4A5;<\/p>\n<p>I did not find a technique to detect the mistake of a missing dot when using standard SwiftUI view modifiers[&#8230;]<\/p>\n<p>But for <em>custom view modifiers there is a simple way<\/em>. We can use the Swift attribute <code>@warn_unqualified_access<\/code> to warn us in Xcode :)<\/p>\n<\/blockquote>\n\n<p id=\"make-your-swiftui-view-modifiers-safer-update-2022-06-02\">Update (2022-06-02): See also: <a href=\"https:\/\/twitter.com\/helje5\/status\/1529433686848032769\">Helge He&szlig;<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Marco Eidinger: Despite the missing qualifier, the code compiles because padding() gets treated as self.padding(). During runtime, that leads to an infinitely recursive View =&gt; stack overflow &#x1F4A5; I did not find a technique to detect the mistake of a missing dot when using standard SwiftUI view modifiers[&#8230;] But for custom view modifiers there is [&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":"2022-06-01T20:04:04Z","apple_news_api_id":"e27c4ad4-1381-4eb0-854b-1bb118ae6745","apple_news_api_modified_at":"2022-06-03T00:01:39Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/A4nxK1BOBTrCFSxuxGK5nRQ","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,2078,30,2077,71,901,1812],"class_list":["post-36042","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-15","tag-mac","tag-macos-12","tag-programming","tag-swift-programming-language","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36042","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=36042"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36042\/revisions"}],"predecessor-version":[{"id":36054,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36042\/revisions\/36054"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=36042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=36042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=36042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}