Observable objects
Next, we are going to look at observable objects, and by observable we mean models that can change state or be updated due to an external API call. For example, a model that houses weather information from a weather API might get updated periodically. We would want our UI (or SwiftUI, in our case) to monitor this model for any changes and implement updates accordingly.
To dig a little deeper into how MVVM works with SwiftUI, let's write a small application that takes some data from an external API, parses the data, and then displays the data within our app.
ObservableObject is a protocol that is part of the new Combine framework, which was announced alongside SwiftUI at WWDC 19. Combine is Swift's own version of Reactive ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access