From the course: Complete Guide to SwiftUI

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

Use ObservedObject in views

Use ObservedObject in views

- [Trainer] Once we have an observable object, we can use at state object and at observed object wrappers to build chains like we did with state and binding. In content view, I'm going to start that chain by redefining orders, so let's go into content view. And we've got show orders, we've got orders here. And I'm going to change this from a state, and I'm going to change it actually to state object. Again, this is a single point of truth, but it works for objects and I'm also going to change how I'm going to do this, is first of all, it can't be private. And I'm going to change this from orders to the order model itself. And we'll start with a full order model in this. So there we've set it up. I could, of course, set it up here in the pizza app. I just did it here for convenience sake. Now, state object makes that object that will stay around and keep our data available while the app is running. Like state, it marks the highest part of the hierarchy that uses observable objects. I…

Contents