8.6 · Lists, ForEach and NavigationStack
Lists and navigation are where identity, state and performance meet. A list shows identified data, and navigation is state you can read and change.
Mental model. A list is data with stable ids. Navigation is a value (a path) that you own, so you can push, pop and restore it from code.
Showing collections
<code>List</code>, <code>ForEach</code> and lazy stacks.
- How do List, ForEach and the lazy stacks differ, and what do they need from your data?
ForEach is not a container: it generates a view per element of a collection and needs an identifier for each, either because the element is Identifiable or…
Moving between screens
<code>NavigationStack</code> and <code>NavigationPath</code>.
- How does NavigationStack work, and how do NavigationPath and navigationDestination fit together?
NavigationStack shows a root view and a stack of pushed destinations, and, unlike the older NavigationView, its stack is state you can read and write. You give…
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.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