











@Stateis 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?
The answer is that
@Statedoes 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.
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.
In this talk, we’ll look at the system that underpins SwiftUI: the attribute graph.
Previously:
Update (2026-05-15): Mindaugas Rudokas:
For an official “documentation” source, this WWDC video has a segment with pretty good illustrated explanation on how AttributeGraph and update cycle of SwiftUI works (starts at 20:47).
iOS iOS 26 Mac macOS Tahoe 26 Programming Swift Programming Language SwiftUI
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。