find any information about Observable macro

Asked on 2025-07-13

1 search

The "observable macro" is a feature introduced in Swift 6.2 that allows developers to opt a class into observation tracking. This is part of the Observation Library, which provides general-purpose APIs for automatically tracking state changes in an object graph. The observable macro is used to broadcast system notifications to registered observers based on a more general observer pattern.

In the session titled "What’s new in Swift" at WWDC 2025, it was explained that you can create an instance of the new observations type with a closure to stream state changes with an async sequence from an observable type. This allows you to observe changes to specific values, such as a player's current state, and receive updates transactionally when observable properties change. This ensures that synchronous updates to multiple properties don't lead to observation updates with the object in an inconsistent state. You can iterate over updated values using a for await loop.

For more details, you can refer to the session What’s new in Swift (12:31).