← All notes
Native iOS Development6 min

An Observations stream is not a Combine publisher

Teams finishing an ObservableObject → @Observable migration still need a place to react outside a view body: persist scene state, mirror a path into analytics, flush a draft when fields settle. Under Combine that often meant objectWillChange.values. @Observable has no objectWillChange. Swift 6.2’s Observations type fills the gap with an AsyncSequence over a closure you write — and that closure is the contract. Treating Observations like a drop-in publisher for “any change on this object” is how Endeo and RuleCaddie scene saves and draft flushes went chatty again after the macro swap looked done.

Two different questions about change

objectWillChange answered “did this ObservableObject announce a mutation?” Subscribers learned that something published, then re-read whatever they cared about. Buffering and debounce lived on the publisher side because the signal itself was coarse.

Observations answers “what is the value of this expression over the model right now, and when did that value change?” You pass a closure that reads @Observable properties — a Codable snapshot, a navigation path, a draft payload — and you get an AsyncSequence of those results. The stream is about the value you named, not about the object’s general mood.

That is why a find-and-replace from objectWillChange.values to Observations { model } is the wrong migration. The old pipeline was object-scoped. The new one is expression-scoped. If you do not name the expression, you have not finished the design.

Transactional coalescing is not debounce you forgot

Observations coalesces synchronous mutations until the next suspension point. Several property writes in one run of code can arrive as a single updated value. That is intentional: you get a settled snapshot instead of a pulse for every field touch.

It is not the same as the Combine debounce or buffer you may have bolted onto objectWillChange to stop SceneStorage thrash. Coalescing ends at await. Suspend too early inside the consumer, or hop threads in a way that splits the transaction, and you see more emissions than the WWDC demo suggested. Suspend too late and you batch work you meant to flush field-by-field.

On device we treat the closure like a pure projection: compute the Data, path, or DTO you intend to persist. Keep I/O in the for-await consumer after the value arrives. Mixing encode-and-write inside the tracked closure turns observation into side effects and makes coalescing harder to reason about.

The stream starts with a value — plan for it

An Observations sequence emits the current value first, then subsequent changes. That is convenient for “always have a snapshot.” It is a footgun if your consumer assumes every emission is a user edit.

Scene restore patterns need an order: apply SceneStorage into the model, then start Observations, or ignore the first emission if restore already wrote storage. Draft autosave that posts analytics on every value will fire once on appear before anyone typed. The bug looks like a double-save after login; the cause is an initial value you treated like a delta.

We write the consumer as if the first element is hydration, not news — same discipline as not treating a tools/list refresh as a new session. Name whether this loop is “keep storage equal to projection” or “react to edits.” Those are different loops even when they share a type.

Availability is part of the architecture

Observations on Apple platforms wants the newer OS line that ships with Swift 6.2’s Observation additions. Apps that still support earlier iOS releases cannot pretend the Combine bridge is gone. A #available path that saves on scenePhase.background for older systems and uses Observations on newer ones is honest. A silently empty else is how TestFlight on an older phone loses navigation state.

withObservationTracking is not a substitute stream either. It is one-shot: the onChange fires once, then tracking stops until you register again. Useful for a UIKit bridge or a single invalidate. Useless as a long-lived save loop unless you re-arm it carefully — which is how teams reinvent a buggy Observations by hand.

Keep the State-vs-StateObject ownership note separate. That note is about how many times the model is constructed. This one is about how change leaves the model toward persistence and other non-view work. Both show up in the same migration PR. They fail for different reasons.

What we check before calling the Observation glue done

Every former objectWillChange subscriber names the projection it actually needed — encoded scene state, selected IDs, draft DTO — and uses that closure with Observations (or an explicit older-OS fallback). No whole-object “ping me” left without a value.

Consumers document initial-value behavior: restore-then-observe, skip first, or idempotent write. A navigation push/pop and a multi-field edit on device produce one storage write per settled snapshot, not one write per property. Analytics hooks are not attached to the same loop as SceneStorage unless product asked for that noise.

If those checks fail, the macro migration is incomplete even when every ObservableObject is gone. Finer view invalidation does not automatically give you a sane AsyncSequence boundary. Observations is the boundary — only after you say what the sequence is a sequence of.

Have something to build?

Tell us what you're working on and we'll tell you honestly whether we're the right fit.

Work with us