Martin
Martin

Reputation: 3

Expression of incompatible type 'id<MKAnnotation>'

I have this piece of code

- (void)pinDropped {
StoreData *myStore = [StoreData sharedStore];

for (NSUInteger i = 0; i < annotations.count; i++) {

    MapViewController *ann = [[_mapView annotations] objectAtIndex:i];

    NSString *myStoreString = [NSString stringWithFormat:@"%@", myStore.myUebergabe];
    NSString *myAnnTitleString = [NSString stringWithFormat:@"%@", ann.title];


    if ([myStoreString isEqual:myAnnTitleString]) {
        [_mapView selectAnnotation:[_mapView.annotations objectAtIndex:i] animated:YES];

    }

} }

which creates this warning in Xcode at *ann:

 Initializing 'MapViewController *__strong' with an expression of incompatible type 'id<MKAnnotation>'

How get I rid of this warning? Everything works fine despite of the warning.

Thank you very much for pointing me in the right direction. Martin

Upvotes: 0

Views: 188

Answers (1)

rmaddy
rmaddy

Reputation: 318904

Change this:

MapViewController *ann = [[_mapView annotations] objectAtIndex:i];

to:

id<MKAnnotation> ann = [[_mapView annotations] objectAtIndex:i];

since [_mapView annotations] returns an array of id<MKAnnotation, not an array of MapViewController.

Upvotes: 1

Related Questions