# binding

[SwiftUI](../..) ⟩ [view](..) ⟩ [state](value) ⟩ binding&#x20;

{% hint style="success" %}
A <mark style="color:purple;">binding</mark> <mark style="color:yellow;">connects</mark> a [property](../../../swift/type/prop) to a [source of truth](../../../master/term/source-of-truth) <mark style="color:yellow;">stored elsewhere</mark>.

Add [@Binding](binding/binding) to create a <mark style="color:yellow;">two-way connection</mark> between a [property](../../../swift/type/prop) that <mark style="color:yellow;">stores data</mark>, and a [view](..) that <mark style="color:yellow;">displays</mark> and <mark style="color:red;">changes</mark> the data.
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}
```swift
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)
        }
    }
}
```
{% endtab %}

{% tab title="👥 相關" %}
*
{% endtab %}
{% endtabs %}
