From the course: Complete Guide to SwiftUI

Unlock this course with a free trial

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

Sheets with completion handlers

Sheets with completion handlers

From the course: Complete Guide to SwiftUI

Sheets with completion handlers

- [Instructor] We'd like to add the sheet OrderDetailView to OrderView as well. However, we have a problem. Trying to pass the order to OrderDetailView won't work here due to the observed nature of orders. If you tried, you'd find you couldn't change anything but the first order. So, we have to take another approach. But this gives us an opportunity to use one more feature of sheets, and that's completion handlers. We'll make a selection, use that in OrderDetailView, then update orders in the completion handler. Head over to OrderView, and let's put some more variables in here so we can put this underneath the Observed object. And we're going to put two more state variables. The first one will be for presenting, so we'll call it presentView. So we'll make presentView a Bool, and that'll be equal to false. And we'll do one more for selected, and we'll make it a noOrderItem. And then let's scroll down to the code here and find the long press gesture. Okay, and we want to know that…

Contents