I am working on swift 2.1 xcode 7 , i have to add multiple Annotations in map view But it's warning
cast from NSMutableArray to unrelated type MKAnnotation always fails
on this code
mapView.addAnnotations(aryNotation as! [MyAnnotation])
for var i = startPoint; i <= endPoint; i++
{
let aryNotation:NSMutableArray = NSMutableArray()
let locationAnnotation = MyAnnotation(coordinate: location,
title: p_user_name!,
subtitle: "",
pinColor: colorofpin,
getTag:i)
/* And eventually add them to the map */
aryNotation.addObject(locationAnnotation)
}
mapView.addAnnotations(aryNotation as! [MyAnnotation])
2nd is when i set map pin image is not working but my code is properly working in swift 2.0 but when i update my code on swift 2.1 latest xcode 7 is not working here is my code for second issue
func mapView(mapView: MKMapView,
viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?{
if annotation is MyAnnotation == false{
return nil
}
/* First typecast the annotation for which the Map View has
fired this delegate message */
let senderAnnotation = annotation as! MyAnnotation
/* We will attempt to get a reusable
identifier for the pin we are about to create */
let pinReusableIdentifier = senderAnnotation.pinColor.rawValue
/* Using the identifier we retrieved above, we will
attempt to reuse a pin in the sender Map View */
var annotationView =
mapView.dequeueReusableAnnotationViewWithIdentifier(
pinReusableIdentifier) as? MKPinAnnotationView
/* If we fail to reuse a pin, then we will create one */
annotationView = MKPinAnnotationView(annotation: senderAnnotation,
reuseIdentifier: pinReusableIdentifier)
//print("senderAnnotation.getTag = = \(senderAnnotation.getTag)")
annotationView?.tag = senderAnnotation.getTag
annotationView!.canShowCallout = true
if(currentIndex == senderAnnotation.getTag)
{
//print("currentIndex===\(currentIndex)")
let pinImage = UIImage(named:"jivemap_pin_o")
annotationView!.image = pinImage
annotationView!.layer.zPosition = 1
}else
{
let pinImage = UIImage(named:"jivemap_pin_g")
annotationView!.image = pinImage
}
return annotationView
}
Maybe both issue are related , Please share your valuable knowledge Regards, Nishant chandwani