From the course: SwiftUI Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Use ObservedObject in views

Use ObservedObject in views

- [Instructor] Once we have an ObservableObject, we can use @StateObject and @ObservedObject wrappers to build chains like we did with State and Binding. In ContentView, I'm going to start that chain by redefining orders. So let's go into ContentView. And we've got showOrders, we've got orders here. And I'm going to change this from a State and I'm going to change it actually to StateObject. 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 OrderModel itself. And we'll start with a full OrderModel in this. So there we've set it up. I could of course set it up here in the HuliPizzaApp. I just did it here for convenience sake. Now, StateObject makes that object that will stay around and keep our data available while the app is running. Like State, it marks the highest…

Contents