# state value

[SwiftUI](/ios/swiftui.md) ⟩ [view](/ios/swiftui/view.md) ⟩ [state](/ios/swiftui/view/state.md) ⟩ value

{% hint style="success" %}
The [state](/ios/master/term/state.md) of a [view](/ios/swiftui/view.md), use [@State](/ios/swiftui/view/state/value/state.md) to <mark style="color:yellow;">declare</mark> and <mark style="color:yellow;">initialize</mark> a <mark style="color:purple;">state value</mark> of a [view](/ios/swiftui/view.md). Also called a <mark style="color:purple;">state property</mark>.
{% endhint %}

```swift
struct ContentView: View {

    // ⭐️ declare & initialize a state value
    @State var isOn = true
    
    // UI
    var body: some View { ... }
    
}
```

* [SwiftUI](/ios/swiftui.md) <mark style="color:yellow;">updates</mark> your views' appearances <mark style="color:yellow;">automatically</mark> whenever your app's <mark style="color:yellow;">state changes</mark>.&#x20;
* One common way to <mark style="color:yellow;">change view states</mark> is through [user interaction](/ios/master/term/user-interaction.md), such as when a person taps a [Button](/ios/swiftui/control/button.md).

{% tabs %}
{% tab title="👥 相關" %}

* [＠State](/ios/swiftui/view/state/value/state.md)：<mark style="color:yellow;">declare</mark> and <mark style="color:yellow;">initialize</mark> a <mark style="color:purple;">state value</mark>&#x20;
* [state object](/ios/swiftui/view/state/object.md)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/swiftui/view/state/value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
