8.1 · What a View is, and how SwiftUI knows which view is which
A SwiftUI view is a cheap description of the interface, not an object on screen. The framework keeps its own long-lived state and uses identity to decide which description is the same view as before.
Mental model. You write a value that describes the screen. SwiftUI compares this description with the last one, by identity, and updates only what changed. State belongs to an identity, not to your struct.
Views as values
The protocol, <code>some View</code> and modifiers.
- What is a View, what does some View mean, and why do modifiers wrap rather than mutate?
A View is a protocol with one requirement: var body: some View. Conforming types are usually small structs, and creating one is cheap: it is a description, not…
Identity
Structural and explicit identity, and what resets state.
- What is structural versus explicit identity in SwiftUI, and what happens to state when identity changes?
SwiftUI needs to know, between two evaluations of body, whether a view is the same view (keep its state, animate the change) or a new one (create fresh state…
More in SwiftUI
- 8.2 · The update loop, dependency tracking and the cost of body
- 8.3 · State, Binding, Environment and Observation
- 8.4 · onAppear, task, onChange and scenes
- 8.5 · The layout negotiation, stacks, GeometryReader, safe area and custom Layout
- 8.6 · Lists, ForEach and NavigationStack
- 8.7 · Animations, PhaseAnimator, Canvas and TimelineView
- 8.8 · Preference keys and coordinate spaces
- 8.9 · Previews and the macros behind SwiftUI
- 8.10 · State, bindings, Observation and environment, checked by running them
- 8.11 · The order of events in a render, and what Swift 6 isolation means for views
- 8.12 · Sharing space, alignment guides, adaptive containers and grids, measured
- 8.13 · What a ViewBuilder produces, and saving and restoring a navigation path