April 2020
Intermediate to advanced
528 pages
15h 40m
English
You learned in Chapter 4 that you create a view controller’s view programmatically by overriding the UIViewController method loadView().
Open MapViewController.swift and override loadView() to create an instance of MKMapView and set it as the view of the view controller. You will need a reference to the map view later on, so create a property for it as well.
Listing 5.1 Creating a map view programmatically (MapViewController.swift)
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() ...Read now
Unlock full access