Need help with the addTarget method (p. 115)

I’m having trouble with the mapTypeChanged method in the WorldTrotter lesson (p. 115). I get errors at each case, specifically “Use of unresolved identifier ‘mapView’.” The code is below.

I don’t know how to fix this problem. Part of the problem is that I don’t understand the syntax. I think self (the first parameter of addTarget) is referring to the instance of MapViewController where this code is defined. The variable mapView is defined in the loadView method.

I am stymied by #selector.

I am 99% sure I have typed in the code exactly as directed in the book. Can anyone help me out?

Here is the line of code that uses the method, from the loadView method that I am overriding:
segmentedControl.addTarget(self, action: #selector(MapViewController.mapTypeChanged(_:)), for: .valueChanged)

Here is the method:
func mapTypeChanged(_ segControl: UISegmentedControl){

    switch segControl.selectedSegmentIndex {
    case 0:
        mapView.mapType = .standard
    case 1:
        mapView.mapType = .hybrid
    case 2:
        mapView.mapType = .satellite

Well, after looking at it some more…I figured it out. mapView should be a global variable in the class. I had defined it in the loadView() method. So no wonder it wasn’t working. Of course I figured it out about two minutes after posting – however, I only posted after trying to figure this out for two hours. I couldn’t figure out how to delete the entire post, or I would have done that.

May I ask how you resolved this issue? I haven’t learned Swift yet so I’m struggling to find an answer. I included a screenshot for reference to the code. Thanks