From 2bde64fcb38ba6309ae32fbdac11d3a7575593c9 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Wed, 21 Sep 2016 10:59:45 -0700 Subject: [PATCH] [ios] fix #6361: source query nullability & return nil for unfound results (#6408) Also removes some dead code in MGLStyle.mm. --- platform/darwin/src/MGLStyle.h | 2 +- platform/darwin/src/MGLStyle.mm | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/platform/darwin/src/MGLStyle.h b/platform/darwin/src/MGLStyle.h index bc4c32da9..585d15c08 100644 --- a/platform/darwin/src/MGLStyle.h +++ b/platform/darwin/src/MGLStyle.h @@ -187,7 +187,7 @@ static const NSInteger MGLStyleDefaultVersion = 9; @return source An instance of an `MGLSource` subclass. */ -- (MGLSource *)sourceWithIdentifier:(NSString *)identifier; +- (nullable MGLSource *)sourceWithIdentifier:(NSString *)identifier; /** Adds a new layer on top of existing layers. diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index c785ef7b6..79d7d7e0f 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -92,19 +92,11 @@ static NSURL *MGLStyleURL_emerald; return @(self.mapView.mbglMap->getStyleName().c_str()); } -- (mbgl::style::Layer *)mbglLayerWithIdentifier:(NSString *)identifier -{ - return self.mapView.mbglMap->getLayer(identifier.UTF8String); -} - -- (mbgl::style::Source *)mbglSourceWithIdentifier:(NSString *)identifier -{ - return self.mapView.mbglMap->getSource(identifier.UTF8String); -} - - (id )layerWithIdentifier:(NSString *)identifier { auto layer = self.mapView.mbglMap->getLayer(identifier.UTF8String); + + if (!layer) return nil; Class clazz = [self classFromLayer:layer]; @@ -119,6 +111,8 @@ static NSURL *MGLStyleURL_emerald; - (MGLSource *)sourceWithIdentifier:(NSString *)identifier { auto s = self.mapView.mbglMap->getSource(identifier.UTF8String); + + if (!s) return nil; Class clazz = [self classFromSource:s];