Swift 6.2 introduces a new API for tracking changes in observable values: the Observations
type. This addition extends Swift’s native observation model by offering a standalone, composable way to monitor updates to @Observable
data — even outside of SwiftUI.
What is Observations
?
Observations<Value, Failure>
is a structure that provides an AsyncSequence
interface. It is initialized using a closure that reads from one or more @Observable
properties. The sequence emits a new value whenever one of those properties changes.
Example
Suppose you have a simple observable model:
@Observable
class Thermometer {
var temperature: Double = 20.0
}
You can observe changes like this:
let sensor = Thermometer()
let temperatureChanges = Observations {
sensor.temperature
}
Now temperatureChanges
is an AsyncSequence
of type Observations<Double, Never>
— it emits temperature readings asynchronously as they change.
To process updates, you can iterate over the sequence using for await
:
for await temp in temperatureChanges {
print("Temperature: \(temp)")
}
Design Goals
This proposal builds on Swift’s ownership and concurrency models to provide:
- A way to observe
@Observable
values in a structured and isolated context. - Compatibility with
AsyncSequence
for ergonomic asynchronous processing. - Support for transactional consistency: observers only see values after a consistent state has been reached.
The observations are transactional, meaning they reflect fully committed updates, not transient intermediate states.
Use Cases
This is useful when you want to observe model values outside of SwiftUI or share state across layers without tightly coupling your architecture to the UI framework.
For example, data-processing logic, background tasks, or unit tests can now hook into @Observable
models using the same principles that SwiftUI relies on — but in a framework-independent way.
If you enjoyed this article, please feel free to follow me on my social media: