Pick the fix
A child Toggle must change the parent's @State var isOn. Which child declaration?
Hint 1 of 1
Who owns isOn?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A @Binding var isOn: Bool, and the parent passes $isOn
Correct. The child reads and writes the parent's value.
Why not the others?
- B
var isOn: Bool, and the parent passesisOn. That passes a copy; the toggle can't change the parent. - C
@State var isOn: Boolinitialized from the parent. That creates a second source of truth that drifts from the parent. - D Post a Notification when the toggle changes. It works, but it is indirect and untyped, and it skips SwiftUI's data flow.