What is @state in the swiftUI?
Asked on 2025-06-16
1 search
In SwiftUI, @State
is a property wrapper used to create a source of truth for a view. When you mark a view property with @State
, SwiftUI manages the storage of that property and provides it back for the view to read and write. This allows the view to react to changes in the state, automatically updating the UI when the state changes.
For example, if you have a view that displays a rating, you can use @State
to keep track of the current rating value. When the user interacts with the view, such as by pressing a button to increment or decrement the rating, SwiftUI will notice the change in state and update the view accordingly.
Here's a brief explanation from the SwiftUI essentials session:
When you mark a view property with
@State
, SwiftUI manages the storage and provides it back for the view to read and write. A binding creates a two-way reference to the state of some other view. SwiftUI maintains the value of this state behind the scenes. When the state changes, SwiftUI calls the view's body again, which returns a new view value, and the result is updated on the screen.

SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.

Optimize SwiftUI performance with Instruments
Discover the new SwiftUI instrument. We’ll cover how SwiftUI updates views, how changes in your app’s data affect those updates, and how the new instrument helps you visualize those causes and effects. To get the most out of this session, we recommend being familiar with writing apps in SwiftUI.

What’s new in SwiftUI
Learn how you can use SwiftUI to build great apps for any Apple platform. Explore a fresh new look and feel for tabs and documents on iPadOS. Improve your window management with new windowing APIs, and gain more control over immersive spaces and volumes in your visionOS apps. We’ll also take you through other exciting refinements that help you make expressive charts, customize and layout text, and so much more.