SwiftUI gives you several property wrappers for holding state, and picking the wrong one is one of the most common sources of confusing bugs for developers new to the framework - a view that doesn't update, or a value that resets unexpectedly. Here's what each one actually does.
Quick Comparison
Wrapper Holds Who creates it Minimum iOS
@State Value types (String, Int, Bool, struct) This view iOS 13+
@StateObject A class conforming to ObservableObject This view (created once) iOS 14+
@ObservedObject A class conforming to ObservableObject Passed in from a parent iOS 13+
@State: Local, View-Owned Value Types
@State is for simple value-type state (a String , Int , Bool , or a struct) that belongs to one view and doesn't need to be shared.…