0PricingLogin
SwiftUI Academy · Lesson

The @Observable Macro

Make a class observable so views track it.

The Problem to Solve

A plain model class holds data, but SwiftUI will not redraw when that data changes. We need to make the class observable.

Meet @Observable

The @Observable macro marks a class so SwiftUI watches its properties and refreshes any view that reads them. ✨

@Observable
class Counter {
    var count = 0
}

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