I can't seem to access a custom MKAnnotation property inside of mapView:viewForAnnotation delegate method. As I understand it, the method takes annotations as values. I'm trying to target the properties of each annotation that gets passed in.
Code
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
//This actually returns a proper coordinate
NSLog(@"%f", annotation.coordinate.latitude);
//This gives me an error: Property 'annotationMarker' not found on object of type '__strong id<MKAnnotation>'
NSLog(@"%@", annotation.annotationMarker);
MKAnnotationView *testPin = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
testPin.image = [UIImage imageNamed:[[testArray objectAtIndex:1]annotationMarker]];
return testPin;
}
I thought maybe the custom property wasn't set correctly, but I'm able to log the property values for these annotations in other parts of the code.
Am I making some kind of syntax error? Does this delegate method strip out custom properties somehow?
You need to cast to your custom MKAnnotation
-conformant class, e.g.
CustomAnnotation *customAnnotation = (CustomAnnotation *)annotation;
NSLog(@"%@", customAnnotation.annotationMarker);