A property wrapper type that can read and write a value managed by SwiftUI.
- iOS 13.0+
- macOS 10.15+
- Mac Catalyst 13.0+
- tvOS 13.0+
- watchOS 6.0+
- Xcode 11.0+
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.
State instance isn’t the value itself; it’s a means of reading and writing the value. To access a state’s underlying value, use its variable name, which returns the
wrapped property value.
You should only access a state property from inside the view’s body, or from methods called by it. For this reason, declare your state properties as private, to prevent clients of your view from accessing it. It is safe to mutate state properties from any thread.
To pass a state property to another view in the view hierarchy, use the variable name with the
$ prefix operator. This retrieves a binding of the state property from its
projected property. For example, in the following code example
Player passes its state property