Ch 34: Maps - Custom annotations won't show up [ SOLVED ]

I completed chapter 34, but for some reason I still see the standard red annotations with the labels underneath them, instead of the custom green ones. I compared my code with the provided examples, but I can’t find any differences.

Any suggestions what I’m missing?

extension MapViewController: MKMapViewDelegate {

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    guard annotation is Location else {
        return nil
    let identifier = "Location"
    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
    if annotationView == nil {
        let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
        pinView.isEnabled = true
        pinView.canShowCallout = true
        pinView.animatesDrop = false
        pinView.pinTintColor = UIColor(red: 0.32, green: 0.82, blue: 0.4, alpha: 1)
        let rightButton = UIButton(type: .detailDisclosure)
        rightButton.addTarget(self, action: #selector(showLocationDetails(_:)), for: .touchUpInside)
        pinView.rightCalloutAccessoryView = rightButton
        annotationView = pinView
    if let annotationView = annotationView {
        annotationView.annotation = annotation
        let button = annotationView.rightCalloutAccessoryView as! UIButton
        if let index = locations.firstIndex(of: annotation as! Location) {
            button.tag = index
    return annotationView


I even replaced all code in Location+CoreDataClass.swift and MapViewController.swift with the code from the completed example, but the annotations are still the standard one.

I figured it out I forgot to connect the Map View Delegate with the the view controller.

@jvantoor Glad you sorted it out! Cheers! :]

This topic was automatically closed after 166 days. New replies are no longer allowed.