Back to Swift Reference Ask BeeAI
📱 SwiftUIBeginneriOS 13+
@State & @Binding
Own simple view-local state with @State and share write access with child views through @Binding.
@State is the source of truth for simple values owned by a view — toggles, text field input, selected tabs. When it changes, SwiftUI re-renders the body.
Pass a $binding to a child view so it can read and write the parent's state without owning it.
state-and-binding.swift
1struct SettingsView: View {
2 @State private var notificationsOn = true
3
4 var body: some View {
5 Form {
6 NotificationToggle(isOn: $notificationsOn)
7 Text(notificationsOn ? "You'll get alerts" : "Muted")
8 }
9 }
10}
11
12struct NotificationToggle: View {
13 @Binding var isOn: Bool
14
15 var body: some View {
16 Toggle("Notifications", isOn: $isOn)
17 }
18}Common pitfalls
- Always mark @State private — it belongs to the view that declares it.
- Do not use @State for data shared across screens; use an @Observable model in the environment.
Still unclear? Ask BeeAI about @State & @Binding.
Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.
Related topics
Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.
See Pro Plans