# state

[terms](https://lochiwei.gitbook.io/ios/master/term) ⟩ state &#x20;

{% hint style="success" %}
The <mark style="color:yellow;">information</mark> stored in a <mark style="color:orange;">variable</mark>, applilcation, or system <mark style="color:yellow;">at a given time</mark>. For example, if a variable `level = 4`, its <mark style="color:yellow;">current</mark> <mark style="color:purple;">state</mark> is `4`.
{% endhint %}

{% hint style="info" %}
[SwiftUI](https://lochiwei.gitbook.io/ios/swiftui) <mark style="color:yellow;">updates</mark> your views' appearances <mark style="color:yellow;">automatically</mark> whenever your app's <mark style="color:purple;">state</mark> changes. One common way to change [view](https://lochiwei.gitbook.io/ios/swiftui/view) <mark style="color:purple;">states</mark> is through [user interaction](https://lochiwei.gitbook.io/ios/master/term/user-interaction), such as when a person taps a Button.

```swift
struct ContentView: View {

    // ⭐️ view state (data)
    @State var isOn = true
    
    // UI
    var body: some View { ... }
    
}
```

{% endhint %}

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

* [property](https://lochiwei.gitbook.io/ios/swift/type/prop)：variable stored inside a type.
* [＠State](https://lochiwei.gitbook.io/ios/swiftui/view/state/value/state)：a [property wrapper](https://lochiwei.gitbook.io/ios/swift/type/prop/wrapper) that tells SwiftUI to manage the storage for a view <mark style="color:purple;">state</mark>.
* [view state](https://lochiwei.gitbook.io/ios/swiftui/view/state/value)：the <mark style="color:purple;">state</mark> of a view
  {% endtab %}
  {% endtabs %}
