8.13 · What a ViewBuilder produces, and saving and restoring a navigation path
Two things that look like magic: how a pile of statements becomes one view type, and how a stack’s path survives a relaunch. Both can be inspected directly.
Mental model. The compiler turns body into a nested generic type that SwiftUI diffs; the navigation path is a list of Hashable values, and saving it saves type names and values.
Types and paths
The type a builder creates, and persisting a NavigationPath.
- What type does a ViewBuilder body actually produce for modifiers, if, several views and AnyView, and why does it matter?
Printing the type of body shows what the compiler built (SDK 27, macOS check). Modifiers nest: ModifiedContent<ModifiedContent<Text, _PaddingLayout>… - How do you save and restore a NavigationPath, and what can go wrong?
A NavigationPath is a type-erased stack of Hashable values. It can produce a CodableRepresentation through path.codable, which is nil unless every element is…
More in SwiftUI
- 8.1 · What a View is, and how SwiftUI knows which view is which
- 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