{"id":34513,"date":"2021-12-21T14:55:27","date_gmt":"2021-12-21T19:55:27","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=34513"},"modified":"2021-12-21T14:55:27","modified_gmt":"2021-12-21T19:55:27","slug":"how-to-find-why-a-swiftui-view-is-updating","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/12\/21\/how-to-find-why-a-swiftui-view-is-updating\/","title":{"rendered":"How to Find Why a SwiftUI View Is Updating"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/luka_bernardi\/status\/1402045202714435585\">Luca Bernardi<\/a> (via <a href=\"https:\/\/iosdevweekly.com\/issues\/538\">Dave Verwer<\/a>):<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/luka_bernardi\/status\/1402045202714435585\">\n<p>SwiftUI has a new, pretty cool, <em>debugging<\/em> utility to help you understand what is causing a view to be reevaluated.<\/p>\n<p>Call <code>Self._printChanges()<\/code> inside the body of a view to print out the changes that have triggered the view update.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/tjw\/status\/1407471758228168704\">Tim Wood<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/tjw\/status\/1407471758228168704\">\n<p>This has been helpful a couple times already -- thanks! But unfortunately it seems to have some rough edges and can report false positives (FB9184397, FB9090652) in the latter report still evaluating the view when there are no changes (currently a big perf problem for us).<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/www.hackingwithswift.com\/quick-start\/swiftui\/how-to-find-which-data-change-is-causing-a-swiftui-view-to-update\">Paul Hudson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.hackingwithswift.com\/quick-start\/swiftui\/how-to-find-which-data-change-is-causing-a-swiftui-view-to-update\"><p>[It] should be called <em>inside<\/em> the <code>body<\/code> property. This means you will temporarily need to add an explicit return to send back your regular view code.<\/p>\n<p>To demonstrate this method in action, here&rsquo;s some sample code where a view relies on an observable object that randomly issues change notifications:<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Luca Bernardi (via Dave Verwer): SwiftUI has a new, pretty cool, debugging utility to help you understand what is causing a view to be reevaluated. Call Self._printChanges() inside the body of a view to print out the changes that have triggered the view update. Tim Wood: This has been helpful a couple times already -- [&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":"2021-12-21T19:55:38Z","apple_news_api_id":"28c6a98b-f2b3-4b37-873a-7a185741f469","apple_news_api_modified_at":"2021-12-21T19:55:38Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AKMapi_KzSzeHOnoYV0H0aQ","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":[56,31,2078,30,2077,71,901,1812],"class_list":["post-34513","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-debugging","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\/34513","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=34513"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34513\/revisions"}],"predecessor-version":[{"id":34514,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34513\/revisions\/34514"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=34513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=34513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=34513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}