Reputation: 55
when i write this method :
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *view =[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
if (view == nil) {
view =[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"pin"];
}
}
there is warning on my *view
object.."Incompatible pointer types initialising MKPinAnnotationView *
with an expression of type MKAnnotationView *
"
what is the solution for this please
Upvotes: 2
Views: 133
Reputation: 7764
If you are sure that you'll get a correct type of annotation using dequeue, than you can cast types simply like this:
MKPinAnnotationView *view = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
The point is that dequeueReusableAnnotationViewWithIdentifier
returns id
type which can be a pointer to any object. So the compiler warns you that types MKPinAnnotationView *
and id
might be incompatible.
Upvotes: 2