Back to Developer Roadmap

@StateObject

src/data/roadmaps/swift-ui/content/stateobject@pKVxtzPgA_88wyGF3dK-7.md

4.01.0 KB
Original Source

@StateObject

@StateObject is a property wrapper used to manage the lifecycle of reference type objects (classes) that hold state for a view. It ensures that the object is created only once when the view appears and persists across view updates, preventing the object from being re-initialized every time the view redraws. This is particularly useful for managing data that needs to be shared and maintained within a specific view's scope.

Visit the following resources to learn more: