Daily iOS
SwiftUI

Observation dependency tracking

In iOS 17 SwiftUI, when one property on an @Observable model changes, only some of the views using that model redraw, not all of them. What does SwiftUI use to decide which views to redraw?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

During body evaluation it records only the properties whose getter was actually called (withObservationTracking), and it invalidates the view only when that property's setter is called, so a view is left alone when a property it didn't read changes.

Share a question