what is @Observable?
Asked on 07/30/2024
1 search
@Observable
is a feature in Swift that allows you to declare a type as observable, meaning that changes to its properties can be observed and reacted to. This is particularly useful in SwiftUI, where the UI needs to update in response to changes in the underlying data model.
In the context of the session "Migrate your app to Swift 6" from WWDC 2024, it is mentioned that a type needs to be observable in SwiftUI. This means that the type conforms to the ObservableObject
protocol, which allows SwiftUI views to automatically update when the data changes.
For more details on how @Observable
is used in Swift 6, you can refer to the session Migrate your app to Swift 6 (17:12).
Relevant Sessions

Meet FinanceKit
Learn how FinanceKit lets your financial management apps seamlessly and securely share on-device data from Apple Cash, Apple Card, and more, with user consent and control. Find out how to request one-time and ongoing access to accounts, transactions, and balances — and how to build great experiences for iOS and iPadOS.

Create a custom data store with SwiftData
Combine the power of SwiftData’s expressive, declarative modeling API with your own persistence backend. Learn how to build a custom data store and explore how to progressively add persistence features in your app. To get the most out of this session, watch “Meet SwiftData” and “Model your schema with SwiftData” from WWDC23.

Migrate your app to Swift 6
Experience Swift 6 migration in action as we update an existing sample app. Learn how to migrate incrementally, module by module, and how the compiler helps you identify code that’s at risk of data races. Discover different techniques for ensuring clear isolation boundaries and eliminating concurrent access to shared mutable state.