Swift observation

Asked on 06/16/2025

1 search

Swift observation is a feature that allows developers to track state changes in an object graph automatically. In Swift 6.2, the Observation Library provides general-purpose APIs for this purpose. You can opt a class into observation tracking using the observable macro. This feature enables you to stream state changes with an async sequence from an observable type, allowing you to react to changes in a transactional manner. Updates are tracked from when any observable properties have their willSet called until the next await where the code suspends. This ensures that synchronous updates to multiple properties don't lead to inconsistent states.

For more details, you can refer to the session What’s new in Swift (12:31) which covers the observation library and its capabilities.