What is @state in the swiftUI

Asked on 06/16/2025

1 search

In SwiftUI, @State is a property wrapper used to create a source of truth for a view. It allows you to declare a piece of state that SwiftUI will manage for you. When you mark a view property with @State, SwiftUI handles the storage and provides it back for the view to read and write. This is particularly useful for managing simple state within a view, such as toggling a switch or updating a counter.

For example, in the session "SwiftUI essentials," it is explained that when you use @State, SwiftUI manages the storage of the state and updates the view when the state changes. This allows for a declarative approach to UI updates, where the UI automatically reflects the current state without needing explicit update calls.

If you want to learn more about how @State works in SwiftUI, you can refer to the session SwiftUI essentials (10:41).