Back to Swift Reference
📱 SwiftUIIntermediateiOS 17+

@Observable (Observation framework)

The modern replacement for ObservableObject/@Published — fine-grained updates with less boilerplate.

Mark a class with @Observable and SwiftUI automatically tracks which properties each view reads, re-rendering only when those change.

Own the model with @State in the view that creates it, pass it down as a plain property, and use @Bindable when a child needs bindings to its properties.

observable-macro.swift
1import Observation
2
3@Observable
4final class CartModel {
5    var items: [String] = []
6    var couponCode = ""
7    var total: Int { items.count * 5 }
8}
9
10struct CartScreen: View {
11    @State private var cart = CartModel()
12
13    var body: some View {
14        VStack {
15            Text("Total: $\(cart.total)")
16            CouponField(cart: cart)
17            Button("Add item") { cart.items.append("Sticker") }
18        }
19    }
20}
21
22struct CouponField: View {
23    @Bindable var cart: CartModel
24
25    var body: some View {
26        TextField("Coupon", text: $cart.couponCode)
27    }
28}

Common pitfalls

  • Do not mix @Observable with @Published or @StateObject — those belong to the older Combine-based ObservableObject.
  • Use @ObservationIgnored for properties that should not trigger view updates.

Still unclear? Ask BeeAI about @Observable (Observation framework).

Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.

Ask BeeAI

Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.

See Pro Plans