Map to restaurant detail

Before we connect our segue, we should create an enumeration (an enum for short) to keep track of our segues. An enum is a user-defined data type that consists of a set of related values:

  1. Right-click on the Misc folder inside the Common folder and select New File.
  2. In the Choose a template for your new file screen, select iOS at the top and then Swift File. Then hit Next.
  3. Name this file Segue and hit Create.
  4. Under import Foundation in the new file, add the following:
enum Segue:String {
case showDetail
case showRating
case showReview
case ShowAllReviews
case restaurantList
case locationList
case showPhotoReview
}

We will eventually need all of these segues, so we can add them once. Whenever we use a new one, I will refer back to this file. The next thing we need is to know when the user taps the detail disclosure of the callout.

In the MapViewController.swift file, add the following under the addMap(_ annotations:) method:

func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
self.performSegue(withIdentifier: Segue.showDetail.rawValue, sender: self)
}

We are using performSegue() to call our custom segue. Now, when you tap the annotation and then the callout, you will go to the restaurant-detail view:

Let's build and run the project by hitting the Play button (or use cmd + R). We can now get to the restaurant detail view from the map.