What is the @State property wrapper in SwiftUI?

Answer

@State is a SwiftUI property wrapper that creates mutable state owned by a view. When a @State value changes, SwiftUI automatically re-renders the view body to reflect the new state — this is the core mechanism of SwiftUI's declarative UI updates. Basic usage: struct CounterView: View { @State private var count = 0 // Owned by this view var body: some View { VStack { Text("Count: \(count)") .font(.largeTitle) Button("Increment") { count += 1 // Triggers re-render! } Button("Decrement") { count -= 1 } Button("Reset") { count = 0 } } } }. Rules: use @State for simple value types (Int, String, Bool, struct); mark as private — state is local to the view and should not be exposed; @State instances are stored outside the view struct (by SwiftUI) so they persist across re-renders of the view. @Binding — share state with child views: struct ToggleView: View { @Binding var isOn: Bool // Refers to parent's state var body: some View { Toggle("Enable", isOn: $isOn) } } // Parent: @State private var enabled = false ToggleView(isOn: $enabled) // Pass binding with $. When to use @State vs @StateObject: @State for value types (simple data); @StateObject for reference types (ObservableObject classes). @State is not for complex or shared state — use @ObservedObject, @StateObject, or @EnvironmentObject for that.