Error: Could not assign value of type NSKVONotifying_MKUserLocation to Park_View.AttractionAnnotation
When using this function:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
let annotationView = AttractionAnnotationView(annotation: annotation, reuseIdentifier: "Attraction")
annotationView.canShowCallout = true
return annotationView
}
This error happened:
Failed to pass value of type NSKVONotifying_MKUserLocation (0x7e8a62b0) to value "Park_View.AttractionAnnotation" (0xf7948).
It works well, but when I try to add CoreLocation to find the user location for my code, I start with this error.
+3
source to share
4 answers
I found out that MKUserLocation is annotation too.
Here is the solution I came out with and it resolves the error.
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if (annotation is MKUserLocation) {
return nil
}
else {
let annotationView = AttractionAnnotationView(annotation: annotation, reuseIdentifier: "Attraction")
annotationView.canShowCallout = true
return annotationView
}
}
+15
source to share