DevPrep

All topics › SwiftUI

What is @Observable (the Observation framework, iOS 17+)?

Middle PRO

The gist

@Observable is a macro from the Observation framework (iOS 17, Swift 5.9) that makes a class observable without Combine. The macro rewrites every stored property into a computed one wrapped with access/withMutation on an ObservationRegistrar. While evaluating body, SwiftUI records exactly which properties were read and invalidates the view only when those change — fine-grained tracking, unlike ObservableObject, where any @Published change redrew every subscriber.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store