Concept
@State
declares a view’s own mutable state. When its value changes, the view automatically updates.@Binding
lets a child view reference and modify a state value that’s owned by a parent view.
Example
struct ParentView: View {
@State private var isOn: Bool = false
var body: some View {
ChildView(isOn: $isOn)
}
}
struct ChildView: View {
@Binding var isOn: Bool
var body: some View {
Toggle("Switch", isOn: $isOn)
}
}