Thursday, May 14, 2026

SwiftUI: @State and the Attribute Graph

Federico Zanetello:

@State is one of the many SwiftUI’s pillars that, once understood, we take for granted and use pretty much everywhere without a second thought. But what is @State? What’s happening behind the scenes?

Nikita Vasilev:

The answer is that @State does not store its value in the struct. The struct holds only a thin token - a reference to a node in an external, long-lived graph maintained by the SwiftUI runtime.

[…]

State in the Attribute Graph is owned by the view that declares it. Lifetime of the graph node is tied to the lifetime of that view’s identity in the hierarchy.

Rens Breur:

As is generally known, SwiftUI hands off some of its work to a private framework called AttributeGraph. In this article we will explore how SwiftUI uses that framework to efficiently update only those parts of an app necessary and to efficiently get the data out of your view graph it needs for rendering your app.

Chris Eidhof:

In this talk, we’ll look at the system that underpins SwiftUI: the attribute graph.

Previously:

Comments RSS · Twitter · Mastodon

Leave a Comment