what is a @State

Asked on 06/18/2025

1 search

In the context of SwiftUI, @State is a property wrapper used to declare a source of truth for a view. When you mark a view property with @State, SwiftUI manages the storage and provides it back for the view to read and write. This allows the view to react to changes in the state, updating the UI accordingly. For example, if you have a view that tracks a rating, you can use @State to keep track of the current rating and update it over time. SwiftUI will automatically update the view when the state changes, ensuring that the UI reflects the current state of the data.

For more details, you can refer to the session SwiftUI essentials (00:10:41).