Unwinding our Done button

Earlier in this book, we added an unwind for our Cancel button. Now, we need to make it so that our Done button can also dismiss the modal, but we also want to capture the selected location when the user is done. Let's add this code next:

  1. Open the ExploreViewController.swift file again and, in the private extension under the unwindLocationCancel() function, add the following code:
@IBAction func unwindLocationDone(segue:UIStoryboardSegue) {    if let viewController = segue.source as? LocationViewController {        selectedCity = viewController.selectedCity        if let location = selectedCity {            headerView.lblLocation.text = location.full        }    }}

The code we just added checks the source of the segue. If its source is a class of ...

Get iOS 12 Programming for Beginners - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.