๐Ÿ”ธbinding

SwiftUI โŸฉ view โŸฉ state โŸฉ binding

A binding connects a property to a source of truth stored elsewhere.

Add @Binding to create a two-way connection between a property that stores data, and a view that displays and changes the data.

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