Creating a MapView the first time

Greeting fellow programmers, I’m farirly new to IOS developing/programming, and going into third week working through the book. The issue I am having is directly after the book ask you to delete the Map view controller from the storyboard and create it through code. I’ve entered in the code for the map view, but when you run the application the only view that is displayed is the convert tab, and I am unable to toggle the map view at this time. Any insight into the issue is welcome and thank you in advance.

import UIKit
import MapKit

class MapViewController: UIViewController {

var mapView: MKMapView!

override func loadView() {
    //create a map view
    mapView = MKMapView()
    
    //set it as *the* view of this View controller
    view = mapView
}




override func viewDidLoad() {
    super.viewDidLoad()
    
    print("MapviewController loaded it's view")
}

}

Show us your code: all of it, including the creation of the MapViewController instance itself.

Hello Ibex10, I’m not sure what I’m not including when you say " including the MapViewController instance itself". does Class MapViewController: UIViewController not create an instance of MapViewController, or did I miss that step? Thanks in advance

After redoing part of chapter 4 up to chapter 5, I figured out what the issue was. The book is calling for deleting the Map View specifically, and not the whole MapViewController label added in the pervious chapter. So my swift file I’m assuming had nothing to reference since the actually controller was deleted from the project.

I appear to be having the same issue when deleting the map view. I have followed the code as specified in the book, but the Map View is a black screen on my emulator when I run the application. I have pasted my code below and have included a screenshot highlighting the Map View I am deleting.

import UIKit
import MapKit

class MapViewController: UIViewController {

var mapView: MKMapView!

override func loadView() {
    //Create a map view
    mapView = MKMapView()
    
    //Set it as the view of this view controller
    view = mapView
}

override func viewDidLoad() {
    super.viewDidLoad()
    
    print("MapViewController loaded its view.")
}

}

![Main.storyboard](upload://qG3o2kjv3ILEzVVC4u1KIlbeufX.jpeg)

After further investigation, the issue is now resolved. It turns out that I forgot to add the MapViewController Class to my custom class under my identity inspector.