> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swiftui/view/state/binding.md).

# binding

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

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

Add [@Binding](/ios/swiftui/view/state/binding/binding.md) to create a <mark style="color:yellow;">two-way connection</mark> between a [property](/ios/swift/type/prop.md) that <mark style="color:yellow;">stores data</mark>, and a [view](/ios/swiftui/view.md) 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 %}
