Adam G
Adam G

Reputation: 1188

Incompatible Pointer with Custom MKAnnotationView

In my taxi app I've created a custom MKAnnotationView to display the driver's estimated location. It's pretty simple:

#import <MapKit/MapKit.h>

@interface EstimatedArrivalView : MKAnnotationView

- (void)setText:(NSString *)min :(NSString *)time;

@end

However, when I try to implement the following code on my ViewController:

EstimatedArrivalView *av = [_fullScreenMapView viewForAnnotation:driverPoint];
[av setText:@"MIN" : [NSString stringWithFormat:@"%d", etaTimeCount]];

I get the following warning:

Incompatible pointer types initializing 'EstimatedArrivalView *' with an expression of type 'MKAnnotationView * _Nullable'

As far as I understand, I'm initializing the EstimatedArrivalView as an MKAnnotationView. So why the warning?

Upvotes: 0

Views: 39

Answers (1)

MSU_Bulldog
MSU_Bulldog

Reputation: 3519

I think to solve this error you should try casting the MKAnnotationView as an EstimatedArrivalView like this:

EstimatedArrivalView *av = (EstimatedArrivalView *)[_fullScreenMapView viewForAnnotation:driverPoint];

Upvotes: 1

Related Questions