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

  1. Migrate your app to Swift 6
  2. A Swift Tour: Explore Swift’s features and design