0PricingLogin
SwiftUI Academy · Lesson

@State for Owned Objects

Own an observable model with @State.

Who Owns the Model

An observable model needs an owner: a view that creates it and keeps it alive for as long as the screen exists.

@State Owns the Instance

Use @State to let a view own an observable model. The view creates it once and holds onto it across redraws.

@State private var model = Counter()

All lessons in this course

  1. From View State to a Model Class
  2. The @Observable Macro
  3. @State for Owned Objects
  4. Sharing Models via @Environment
← Back to SwiftUI Academy