[ios] Silence incompatible type warning for callout view (#8608)

This silences a compatibility warning that was introduced in a previous
refactor that changed the return type of the callout view for
annotation delegate method. This also adds checks to ensure that the
callout view provided by the delegate to the map view is of the correct
type and conforms to the correct protocol.
This commit is contained in:
Jesse Bounds
2017-04-04 15:25:59 -07:00
committed by GitHub
parent e34b471842
commit ff73371216
2 changed files with 9 additions and 2 deletions

View File

@@ -1739,7 +1739,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
}];
}
- (UIView<MGLCalloutView> *)mapView:(__unused MGLMapView *)mapView calloutViewForAnnotation:(id<MGLAnnotation>)annotation
- (nullable id <MGLCalloutView>)mapView:(__unused MGLMapView *)mapView calloutViewForAnnotation:(id<MGLAnnotation>)annotation
{
if ([annotation respondsToSelector:@selector(title)]
&& [annotation isKindOfClass:[MBXCustomCalloutAnnotation class]])

View File

@@ -3777,7 +3777,14 @@ public:
UIView <MGLCalloutView> *calloutView;
if ([self.delegate respondsToSelector:@selector(mapView:calloutViewForAnnotation:)])
{
calloutView = [self.delegate mapView:self calloutViewForAnnotation:annotation];
id providedCalloutView = [self.delegate mapView:self calloutViewForAnnotation:annotation];
if (providedCalloutView) {
if (![providedCalloutView isKindOfClass:[UIView class]]) {
[NSException raise:NSInvalidArgumentException format:@"Callout view must be a kind of UIView"];
}
NSAssert([providedCalloutView conformsToProtocol:@protocol(MGLCalloutView)], @"callout view must conform to MGLCalloutView");
calloutView = providedCalloutView;
}
}
if (!calloutView)
{