From the course: Swift 5: Protocol-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Presenting weather data

Presenting weather data

From the course: Swift 5: Protocol-Oriented Programming

Start my 1-month free trial

Presenting weather data

- [Instructor] We've implemented the model and the view model. In this video, we're going to add the missing link that allows the view to reflect changes in the model. The view model conforms to the observable object protocol and has a published property. SwiftUI can observe this property, and that happens almost automatically. Let's switch to the content view. We need to tell SwiftUI which type has the data it should observe. As we know, that's the weather view model class. Let's create the new property with the view model and initialize it. To allow SwiftUI to observe the published properties, we've got to mark the property using the observed object property wrapper. Bear in mind that you can only use the observed object with a type that conforms to the observable object protocol. And we're done with the data binding part. Next, update the text view at line 23 to display the weather view model's weather info…

Contents