🔸binding

SwiftUIviewstate ⟩ binding

struct ContainerView: View {
    
    // ⭐️ container's view state (source of truth)
    @State var isOn = false
    
    var body: some View {
        VStack {
            // ⭐️ 在 subview (Toggle) 中使用 binding ($isOn)
            Toggle("Press Me", isOn: $isOn)
        }
    }
}

Last updated

Was this helpful?