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:
- In the Navigator panel, right-click on the Controller folder in the Map folder and select New File.
- In the Choose a template for your new file screen, select iOS at the top and then Cocoa Touch Class. Then, hit Next.
- Add the following to the Options screen that appears:
New file:
-
- Class: MapViewController
- Subclass: UIViewController
- Also create XIB: Unchecked
- Language: Swift
- Click Next and then Create.
- Under the import UIKit statement, add import MapKit.
- Update your class declaration to include the following protocol:
class MapViewController: UIViewController, ...