Stage 2 · Lesson 6 of 10
@State and bindings
@State marks a value that a view owns, such as whether a sheet is showing or the text in a field. It is local UI state. stores it outside the view and redraws the view when it changes.
Mark it private, because it belongs to that view alone. Sometimes a child view needs to change a value its parent owns. Then the child takes a @Binding, a two-way link to that value.
The parent passes it with the $ prefix, as in Toggle("Wi-Fi", isOn: $isOn). Built-in controls like TextField and Toggle all work through . Sharing state between screens with @Observable comes in the next stage.
Common trapgiving a child its own @State copy of the parent's value, so the two quietly drift apart.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CourseFreeSwiftUI Tutorials (Apple)
Apple · Beginner
Apple's own path from views and stacks to lists and navigation
- CourseFree100 Days of SwiftUI
Paul Hudson (Hacking with Swift) · Beginner
Days 16 to 35 build six small apps on views, modifiers, lists and animation