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
From the course: Swift 5: Protocol-Oriented Programming
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Weather app design2m 32s
-
Defining the UI using SwiftUI4m 20s
-
(Locked)
The WebServiceController protocol5m 13s
-
(Locked)
Working with a third-party API52s
-
(Locked)
Implementing the OpenWeatherMap controller4m 9s
-
(Locked)
Completing the OpenWeatherMap controller2m 42s
-
(Locked)
Introducing the view model3m 8s
-
(Locked)
Presenting weather data2m 39s
-
(Locked)
Challenge: Integrating a fallback service2m 34s
-
(Locked)
Solution: Integrating a fallback service4m 8s
-
-