Property Wrapper | Purpose | Ownership | Lifetime | Ideal Use Case |
---|---|---|---|---|
@State | Local, private value type state for a single view. | View | View's lifetime | Simple UI state (toggles, text fields, counters) |
@Binding | Two-way connection to a value owned by an ancestor view. | Ancestor View | Ancestor's state's lifetime | Passing mutable state to child/reusable components |
ObservableObject | (Protocol) A class that can emit changes to its @Published properties. |
N/A | Depends on how it's created (@StateObject , etc.) |
Complex data models, services, network data |
@StateObject | Creates and owns an instance of an ObservableObject within a view. |
View | View's lifetime | When a view is the primary owner of an ObservableObject |
@EnvironmentObject | Accesses an ObservableObject provided by an ancestor in the environment. |
Ancestor View | Ancestor's environment object's lifetime | Global, shared, application-wide data |
Last active
July 21, 2025 16:41
-
-
Save wilsolutions/33b76af65692422664f526dd5be9229b to your computer and use it in GitHub Desktop.
SwiftUI
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment