SwiftUI
Intermediate 3 min read
@State vs @StateObject
Choose the right property wrapper for your data source
iOS Academy
iOS Engineer
@State is for simple value types (Int, String, Bool) that the view owns. SwiftUI recreates the view's body but preserves @State storage across re-renders. @StateObject is for ObservableObject instances — SwiftUI creates the object once and keeps it alive for the view's lifetime. Never use @ObservedObject to instantiate a view model; it gets recreated on every re-render.
#SwiftUI
#state
#ObservableObject