diff options
Diffstat (limited to 'platform/darwin/src')
4 files changed, 34 insertions, 22 deletions
diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index fee34b4b71..376bf5e73b 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -291,7 +291,7 @@ private: // Private utilities for converting from mbgl to mgl values } // Array - static ObjCType toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) { + static NSArray<NSExpression*> *toMGLRawStyleValue(const std::vector<MBGLElement> &mbglStopValue) { NSMutableArray *array = [NSMutableArray arrayWithCapacity:mbglStopValue.size()]; for (const auto &mbglElement: mbglStopValue) { [array addObject:[NSExpression expressionForConstantValue:toMGLRawStyleValue(mbglElement)]]; diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 9dad00e56e..fe2e5a0a31 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -792,19 +792,24 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } else if ([curveType isEqualToString:@"cubic-bezier"]) { curveParameters = @[@"literal", [interpolationOptions subarrayWithRange:NSMakeRange(1, 4)]]; } - NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters]; - argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; - NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject]; - NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2]; - NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator; - while (NSNumber *key = stopEnumerator.nextObject) { - NSExpression *valueExpression = stopEnumerator.nextObject; - stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression]; + + NSAssert(curveParameters, @"curveParameters should be non-nil"); + if (curveParameters) { + NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters]; + argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject]; + NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2]; + NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator; + while (NSNumber *key = stopEnumerator.nextObject) { + NSExpression *valueExpression = stopEnumerator.nextObject; + stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression]; + } + NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; + return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" + arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]]; } - NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; - return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" - arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]]; + } else if ([op isEqualToString:@"step"]) { NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects[0]]; NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; @@ -823,9 +828,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { minimum = [NSExpression expressionWithMGLJSONObject:valueExpression]; } } - NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; - return [NSExpression expressionForFunction:@"mgl_step:from:stops:" - arguments:@[inputExpression, minimum, stopExpression]]; + + NSAssert(minimum, @"minimum should be non-nil"); + if (minimum) { + NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; + return [NSExpression expressionForFunction:@"mgl_step:from:stops:" + arguments:@[inputExpression, minimum, stopExpression]]; + } + } else if ([op isEqualToString:@"zoom"]) { return NSExpression.zoomLevelVariableExpression; } else if ([op isEqualToString:@"heatmap-density"]) { @@ -1021,7 +1031,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } case NSKeyPathExpressionType: { - NSArray *expressionObject; + NSArray *expressionObject = @[]; NSArray *keyPath = [self.keyPath componentsSeparatedByString:@"."]; for (NSString *pathComponent in keyPath) { if (expressionObject) { @@ -1030,6 +1040,8 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { expressionObject = @[@"get", pathComponent]; } } + + NSAssert(expressionObject.count > 0, @"expressionObject should be non-empty"); return expressionObject; } diff --git a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h index 4ef49a2d15..54bc9068f4 100644 --- a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h +++ b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h @@ -13,8 +13,8 @@ NS_ASSUME_NONNULL_BEGIN @interface NSObject (MGLExpressionAdditions) -- (NSNumber *)mgl_number; -- (NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... NS_REQUIRES_NIL_TERMINATION; +- (nullable NSNumber *)mgl_number; +- (nullable NSNumber *)mgl_numberWithFallbackValues:(id)fallbackValue, ... NS_REQUIRES_NIL_TERMINATION; @end diff --git a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h index 1828009678..051a2775a1 100644 --- a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h +++ b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h @@ -10,15 +10,15 @@ NS_ASSUME_NONNULL_BEGIN - (mbgl::style::Filter)mgl_filter; -+ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter; ++ (nullable instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter; @end @interface NSPredicate (MGLExpressionAdditions) -- (id)mgl_if:(id)firstValue, ...; +- (nullable id)mgl_if:(id)firstValue, ...; -- (id)mgl_match:(NSExpression *)firstCase, ...; +- (nullable id)mgl_match:(NSExpression *)firstCase, ...; @end |