Should I used @ObservedObject ?

Asked on 08/02/2024

1 search

Yes, you should use @ObservedObject in SwiftUI when you need to observe an external object that conforms to the ObservableObject protocol. This is particularly useful when you have a reference type that you want to share across multiple views and you need those views to update when the data changes.

In the session SwiftUI essentials, it is explained that any piece of data that a view uses in its body is a dependency of that view. SwiftUI will call the view's body again with the updated data when the observed object changes. This is crucial for keeping your UI in sync with your data model.

For more detailed information, you can refer to the chapter "Fundamentals of views" in the SwiftUI essentials session.