Creating our Map View Controller 

We need to create our MapViewController file and then connect it with our UIViewController and map view in the storyboard. First, let's create this file:

  1. In the Navigator panel, right-click on the Controller folder in the Map folder and select New File.
  2. In the Choose a template for your new file screen, select iOS at the top and then Cocoa Touch Class. Then, hit Next.
  3. Add the following to the Options screen that appears:

New file:

    • Class: MapViewController
    • Subclass: UIViewController
    • Also create XIB: Unchecked
    • Language: Swift
  1. Click Next and then Create.
  2. Under the import UIKit statement, add import MapKit.
  3. Update your class declaration to include the following protocol:
class MapViewController: UIViewController, ...

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.