Generic Structure


A persistent value of a given type, through which a view reads and monitors the value.


@frozen @propertyWrapper struct State<Value>


SwiftUI manages the storage of any property you declare as a state. When the state value changes, the view invalidates its appearance and recomputes the body. Use the state as the single source of truth for a given view.

A State instance isn’t the value itself; it’s a means of reading and mutating the value. To access a state’s underlying value, use its value property.

Only access a state property from inside the view’s body (or from functions called by it). For this reason, you should declare your state properties as private, to prevent clients of your view from accessing it.

You can get a binding from a state with the `binding` property, or by using the `$` prefix operator.




Creates a state without an initial value.

init(initialValue: Value)

Creates the state with the specified initial value.

Instance Methods

func update()

Called immediately before the view’s body() function is executed, after updating the values of any link variables stored in self.


Conforms To

See Also

Data-Dependent Views

struct EnvironmentObject

A dynamic view property that uses a bindable object supplied by an ancestor view to invalidate the current view whenever the bindable object changes.

protocol DynamicProperty

A stored variable that updates an external property of a view.