I upgraded to a newer Swift compiler and ran into this compiler error I can’t figure out how to resolve. I have a bunch of mapView functions declared from the MKMapViewDelegate. They all seem to match up except this one which throws this error:
ViewController.swift:137:10: Objective-C method 'mapView:viewForAnnotation:' provided by method 'mapView(:viewForAnnotation:)' conflicts with optional requirement method 'mapView(:viewForAnnotation:)' in protocol ‘MKMapViewDelegate’
ViewController.swift:12:7: Class 'ViewController' declares conformance to protocol 'MKMapViewDelegate’ here
/ViewController.swift:137:10: Requirement 'mapView(_:viewForAnnotation:)' declared here (MapKit.MKMapViewDelegate)
I looked at MKMapViewDelegate method and I thought I was matching it up correctly so I am baffled as to what has changed that needs correction. From there I see
optional func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
Here’s my declaration below that throws the error.
class ViewController: UIViewController, MKMapViewDelegate {
func mapView(aMapView: MKMapView!, viewForAnnotation annotation: CustomMapPinAnnotation!) -> MKAnnotationView! {
//The error is thrown here on the m in mapView
}
}