@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.
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.
Related topics
Own simple view-local state with @State and share write access with child views through @Binding.
Share models and system values down the view tree without passing them through every initializer.
Value types vs reference types — and why SwiftUI and Swift concurrency favor structs.
Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.
See Pro Plans