TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Project16 Day 60: Map pins not showing

Forums > 100 Days of Swift

I have completed Project16 by following the instructions as far as I can tell, but in the end it isn't showing the map pins at all anymore.

When I add this function as instructed here, it causes the map pins to stop showing. But if I delete or comment out this function then it shows the map pins, just without annotation information available.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        guard annotation is Capital else { return nil }
        let identifier = "Capital"
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)        

        if annotationView == nil {
            annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView?.canShowCallout = true

            let btn = UIButton(type: .detailDisclosure)
            annotationView?.rightCalloutAccessoryView = btn
        } else {
            annotationView?.annotation = annotation
        }

        return annotationView
}

I've looked over this function a few times now and can't seem to find any differences between this and what Paul gave us in the instructions. Does anybody know how to make this work?

And yes, I have made my ViewController the Delegate for the MKMapView and made it conform to MKMapViewDelegate as instructed.

3      

Nevermind, I found the problem. I was using the initializer for MKAnnotationView(annotation:, reuseIdentifier:) instead of MKPinAnnotationView(annotation:, reuseIdentifier:)

However, after trying to use that, I found that it was depricated, so I ended up using MKMarkerAnnotationView(annotation:, reuseIdentifier:) instead, and now it is working as expected.

3      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.