Quantcast
Channel: Debugging – Michael Tsai
Viewing all articles
Browse latest Browse all 170

How to Find Why a SwiftUI View Is Updating

$
0
0

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 -- 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).

Paul Hudson:

[It] should be called inside the body property. This means you will temporarily need to add an explicit return to send back your regular view code.

To demonstrate this method in action, here’s some sample code where a view relies on an observable object that randomly issues change notifications:


Viewing all articles
Browse latest Browse all 170

Trending Articles