From 2fde39d59f0f8a40e0d7a2b9b48179ea354e343c Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 12 Apr 2018 12:58:43 -0400 Subject: [PATCH 1/9] [ios, macos] Refactor convinience expression initializers. # Conflicts: # platform/darwin/src/NSExpression+MGLAdditions.h # platform/darwin/src/NSExpression+MGLAdditions.mm # platform/ios/app/MBXViewController.m --- .../darwin/src/NSExpression+MGLAdditions.h | 111 ++++++++++++++++++ .../darwin/src/NSExpression+MGLAdditions.mm | 64 +++++++++- platform/ios/app/MBXViewController.m | 15 ++- 3 files changed, 183 insertions(+), 7 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index a0081cb4288..b7a0a6e3be8 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -9,6 +9,74 @@ NS_ASSUME_NONNULL_BEGIN +typedef NSString *MGLExpressionInterpolationMode NS_TYPED_EXTENSIBLE_ENUM; + +/** + An `NSString` identifying the `linear` interpolation type in an `NSExpression`. + + This attribute corresponds to the `linear` value in the + interpolate + expression reference in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolationModeLinear; + +/** + An `NSString` identifying the `expotential` interpolation type in an `NSExpression`. + + This attribute corresponds to the `exponential` value in the + interpolate + expression reference in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolationModeExponential; + +/** + An `NSString` identifying the `cubic-bezier` interpolation type in an `NSExpression`. + + This attribute corresponds to the `cubic-bezier` value in the + interpolate + expression reference in the Mapbox Style Specification. + */ +extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier; + +@interface NSExpression (MGLVariableAdditions) + +/** + `NSExpression` attribute that corresponds to the + zoom + expression reference in the Mapbox Style Specification. + */ ++ (NSExpression *)mgl_zoomLevelVariableExpression; + +/** + `NSExpression` attribute that corresponds to the + heatmap-density + expression reference in the Mapbox Style Specification. + */ ++ (NSExpression *)mgl_heatmapVariableExpression; + +/** + `NSExpression` attribute that corresponds to the + geometry-type + expression reference in the Mapbox Style Specification. + */ ++ (NSExpression *)mgl_geometryTypeVariableExpression; + +/** + `NSExpression` attribute that corresponds to the + id + expression reference in the Mapbox Style Specification. + */ ++ (NSExpression *)mgl_featureIdentifierVariableExpression; + +/** + `NSExpression` attribute that corresponds to the + properties + expression reference in the Mapbox Style Specification. + */ ++ (NSExpression *)mgl_featurePropertiesVariableExpression; + +@end + @interface NSExpression (MGLAdditions) /** @@ -44,6 +112,49 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly) id mgl_jsonExpressionObject; +/** + Returns a conditional function expression specifying the string predicate, and + expressions for each condition. + + @param conditionPredicate The predicate to get evaluated. + @param trueExpression The expression for conditions equal to true. + @param falseExpression The expression for conditions equal to false. + */ ++ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression; + +/** + Returns a step function expression specifying the function operator, default expression + and stops. + + @param operatorExpression The operator expression. + @param expression The expression which could be a constant or function expression. + @param stops The stops dictionay must be numeric literals in strictly ascending order. + */ ++ (instancetype)mgl_expressionForStepFunction:(nonnull NSExpression*)operatorExpression defaultExpression:(nonnull NSExpression *)expression stops:(nonnull NSExpression*)stops; + +/** + Returns an interpolated function expression specifying the function operator, curve type, + parameters and steps. + + @param expressionOperator The expression operator. + @param curveType The curve type could be `MGLExpressionInterpolationModeLinear`, + `MGLExpressionInterpolationModeExponential` and + `MGLExpressionInterpolationModeCubicBezier`. + @param parameters The parameters expression. + @param steps The steps expression. + */ ++ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)expressionOperator curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps; + + +/** + Returns a string constant expression appending the passed expression. + + @param string The string to append. + system’s preferred language, if supported, specify `nil`. To use the local + language, specify a locale with the identifier `mul`. + */ +- (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)string; + /** Returns a copy of the receiver localized into the given locale. diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index be6eef7f47d..8d4fb46fefd 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -16,6 +16,10 @@ #import +const MGLExpressionInterpolationMode MGLExpressionInterpolationModeLinear = @"linear"; +const MGLExpressionInterpolationMode MGLExpressionInterpolationModeExponential = @"exponential"; +const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = @"cubic-bezier"; + @interface MGLAftermarketExpressionInstaller: NSObject @end @@ -557,6 +561,30 @@ - (id)mgl_has:(id)element { [NSException raise:NSInvalidArgumentException format:@"Has expressions lack underlying Objective-C implementations."]; return nil; + +} + +@end +@implementation NSExpression (MGLVariableAdditions) + ++ (NSExpression *)mgl_zoomLevelVariableExpression { + return [NSExpression expressionForVariable:@"zoomLevel"]; +} + ++ (NSExpression *)mgl_heatmapVariableExpression { + return [NSExpression expressionForVariable:@"heatmapDensity"]; +} + ++ (NSExpression *)mgl_geometryTypeVariableExpression { + return [NSExpression expressionForVariable:@"mgl_geometryType"]; +} + ++ (NSExpression *)mgl_featureIdentifierVariableExpression { + return [NSExpression expressionForVariable:@"mgl_featureIdentifier"]; +} + ++ (NSExpression *)mgl_featurePropertiesVariableExpression { + return [NSExpression expressionForVariable:@"mgl_featureProperties"]; } @end @@ -591,6 +619,25 @@ @implementation NSExpression (MGLAdditions) return subexpressions; } ++ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression { + if (@available(iOS 9.0, *)) { + return [NSExpression expressionForConditional:conditionPredicate trueExpression:trueExpression falseExpression:falseExpression]; + } else { + return [NSExpression expressionForFunction:@"MGL_IF" arguments:@[[NSExpression expressionWithFormat:@"%@", conditionPredicate], trueExpression, falseExpression]]; + } +} + ++ (instancetype)mgl_expressionForStepFunction:(NSExpression *)operatorExpression defaultExpression:(NSExpression *)expression stops:(nonnull NSExpression *)stops { + return [NSExpression expressionForFunction:@"mgl_step:from:stops:" + arguments:@[operatorExpression, expression, stops]]; +} + ++ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)expressionOperator curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps { + NSExpression *sanitizeParams = parameters ? parameters : [NSExpression expressionForConstantValue:nil]; + return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" + arguments:@[expressionOperator, [NSExpression expressionForConstantValue:curveType], sanitizeParams, steps]]; +} + + (instancetype)expressionWithMGLJSONObject:(id)object { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -767,15 +814,15 @@ + (instancetype)expressionWithMGLJSONObject:(id)object { return [NSExpression expressionForFunction:@"mgl_step:from:stops:" arguments:@[inputExpression, minimum, stopExpression]]; } else if ([op isEqualToString:@"zoom"]) { - return [NSExpression expressionForVariable:@"zoomLevel"]; + return NSExpression.mgl_zoomLevelVariableExpression; } else if ([op isEqualToString:@"heatmap-density"]) { - return [NSExpression expressionForVariable:@"heatmapDensity"]; + return NSExpression.mgl_heatmapVariableExpression; } else if ([op isEqualToString:@"geometry-type"]) { - return [NSExpression expressionForVariable:@"geometryType"]; + return NSExpression.mgl_geometryTypeVariableExpression; } else if ([op isEqualToString:@"id"]) { - return [NSExpression expressionForVariable:@"featureIdentifier"]; + return NSExpression.mgl_featureIdentifierVariableExpression; } else if ([op isEqualToString:@"properties"]) { - return [NSExpression expressionForVariable:@"featureProperties"]; + return NSExpression.mgl_featurePropertiesVariableExpression; } else if ([op isEqualToString:@"var"]) { return [NSExpression expressionForVariable:argumentObjects.firstObject]; } else if ([op isEqualToString:@"case"]) { @@ -827,6 +874,13 @@ + (instancetype)expressionWithMGLJSONObject:(id)object { return nil; } +- (instancetype)mgl_appendingString:(NSString *)string { + return [self mgl_appendingExpression:[NSExpression mgl_expressionForString:string]]; +} +- (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)expression { + return [NSExpression expressionForFunction:self selectorName:@"stringByAppendingString:" arguments:@[expression]]; +} + - (id)mgl_jsonExpressionObject { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 0a76f8c0c50..989b8480555 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -967,9 +967,14 @@ - (void)styleWaterLayer @10.0f: [UIColor redColor], @12.0f: [UIColor greenColor], @14.0f: [UIColor blueColor]}; + NSExpression *fillColorExpression = [NSExpression mgl_expressionForInterpolateFunction:NSExpression.mgl_zoomLevelVariableExpression + curveType:MGLExpressionInterpolationModeLinear + parameters:nil + steps:[NSExpression expressionForConstantValue:waterColorStops]]; waterLayer.fillColor = [NSExpression expressionWithFormat: @"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", waterColorStops]; + waterLayer.fillColor = fillColorExpression; NSDictionary *fillAntialiasedStops = @{@11: @YES, @12: @NO, @@ -1467,10 +1472,16 @@ - (void)stylePolygonWithDDS { // source, categorical function that sets any feature with a "fill" attribute value of true to red color and anything without to green MGLFillStyleLayer *fillStyleLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fill-layer" source:shapeSource]; - fillStyleLayer.fillColor = [NSExpression expressionWithFormat:@"TERNARY(fill == YES, %@, %@)", [UIColor greenColor], [UIColor redColor]]; + fillStyleLayer.fillColor = [NSExpression mgl_expressionForConditional:[NSPredicate predicateWithFormat:@"fill == YES"] + trueExpression:[NSExpression expressionForConstantValue:[UIColor greenColor]] + falseExpresssion:[NSExpression expressionForConstantValue:[UIColor redColor]]]; + + // source, identity function that sets any feature with an "opacity" attribute to use that value and anything without to 1.0 - fillStyleLayer.fillOpacity = [NSExpression expressionWithFormat:@"TERNARY(opacity != nil, opacity, 1.0)"]; + fillStyleLayer.fillOpacity = [NSExpression mgl_expressionForConditional:[NSPredicate predicateWithFormat:@"opacity != nil"] + trueExpression:[NSExpression expressionForKeyPath:@"opacity"] + falseExpresssion:[NSExpression expressionForConstantValue:@1.0]]; [self.mapView.style addLayer:fillStyleLayer]; } From 4e918863a8cafc8e83ef19b63ebdfcfde83af272 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Thu, 12 Apr 2018 19:11:33 -0400 Subject: [PATCH 2/9] [ios, macos] Add MGL_MATCH convenience method. # Conflicts: # platform/darwin/src/NSExpression+MGLAdditions.h # platform/darwin/src/NSExpression+MGLAdditions.mm # platform/darwin/test/MGLExpressionTests.mm --- .../darwin/src/NSExpression+MGLAdditions.h | 86 ++++++++++--------- .../darwin/src/NSExpression+MGLAdditions.mm | 63 ++++++++------ platform/darwin/test/MGLExpressionTests.mm | 50 +++++++++++ 3 files changed, 134 insertions(+), 65 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index b7a0a6e3be8..033ca63d020 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -52,7 +52,7 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio heatmap-density expression reference in the Mapbox Style Specification. */ -+ (NSExpression *)mgl_heatmapVariableExpression; ++ (NSExpression *)mgl_heatmapDensityVariableExpression; /** `NSExpression` attribute that corresponds to the @@ -77,40 +77,7 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio @end -@interface NSExpression (MGLAdditions) - -/** - Returns an expression equivalent to the given Foundation object deserialized - from JSON data. - - The Foundation object is interpreted according to the - [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). - See the - “[Information for Style Authors](../for-style-authors.html#setting-attribute-values)” - guide for a correspondence of operators and types between the style - specification and the `NSExpression` representation used by this SDK. - - @param object A Foundation object deserialized from JSON data, for example - using `NSJSONSerialization`. - @return An initialized expression equivalent to `object`, suitable for use as - the value of a style layer attribute. - */ -+ (instancetype)expressionWithMGLJSONObject:(id)object NS_SWIFT_NAME(init(mglJSONObject:)); - -/** - An equivalent Foundation object that can be serialized as JSON. - - The Foundation object conforms to the - [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). - See the - “[Information for Style Authors](../for-style-authors.html#setting-attribute-values)” - guide for a correspondence of operators and types between the style - specification and the `NSExpression` representation used by this SDK. - - You can use `NSJSONSerialization` to serialize the Foundation object as data to - write to a file. - */ -@property (nonatomic, readonly) id mgl_jsonExpressionObject; +@interface NSExpression (MGLInitializerAdditions) /** Returns a conditional function expression specifying the string predicate, and @@ -126,25 +93,26 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio Returns a step function expression specifying the function operator, default expression and stops. - @param operatorExpression The operator expression. - @param expression The expression which could be a constant or function expression. + @param input The input expression. + @param from The expression which could be a constant or function expression. @param stops The stops dictionay must be numeric literals in strictly ascending order. */ -+ (instancetype)mgl_expressionForStepFunction:(nonnull NSExpression*)operatorExpression defaultExpression:(nonnull NSExpression *)expression stops:(nonnull NSExpression*)stops; ++ (instancetype)mgl_expressionForStepFunction:(nonnull NSExpression*)input from:(nonnull NSExpression *)from stops:(nonnull NSExpression*)stops; /** Returns an interpolated function expression specifying the function operator, curve type, parameters and steps. - @param expressionOperator The expression operator. + @param input The expression input. @param curveType The curve type could be `MGLExpressionInterpolationModeLinear`, `MGLExpressionInterpolationModeExponential` and `MGLExpressionInterpolationModeCubicBezier`. @param parameters The parameters expression. @param steps The steps expression. */ -+ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)expressionOperator curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps; ++ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)input curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps; ++ (instancetype)mgl_expressionForMatchFunction:(nonnull NSExpression*)condition values:(nonnull NSExpression *)values defaultValue:(nonnull NSExpression *)defaultValue; /** Returns a string constant expression appending the passed expression. @@ -155,6 +123,44 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio */ - (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)string; +@end + +@interface NSExpression (MGLAdditions) + +/** + Returns an expression equivalent to the given Foundation object deserialized + from JSON data. + + The Foundation object is interpreted according to the + [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). + See the + “[Information for Style Authors](../for-style-authors.html#setting-attribute-values)” + guide for a correspondence of operators and types between the style + specification and the `NSExpression` representation used by this SDK. + + @param object A Foundation object deserialized from JSON data, for example + using `NSJSONSerialization`. + @return An initialized expression equivalent to `object`, suitable for use as + the value of a style layer attribute. + */ ++ (instancetype)expressionWithMGLJSONObject:(id)object NS_SWIFT_NAME(init(mglJSONObject:)); + +/** + An equivalent Foundation object that can be serialized as JSON. + + The Foundation object conforms to the + [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). + See the + “[Information for Style Authors](../for-style-authors.html#setting-attribute-values)” + guide for a correspondence of operators and types between the style + specification and the `NSExpression` representation used by this SDK. + + @param locale The locale into which labels should be localized. To use the + You can use `NSJSONSerialization` to serialize the Foundation object as data to + write to a file. + */ +@property (nonatomic, readonly) id mgl_jsonExpressionObject; + /** Returns a copy of the receiver localized into the given locale. diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 8d4fb46fefd..1dae31d9fc2 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -571,7 +571,7 @@ + (NSExpression *)mgl_zoomLevelVariableExpression { return [NSExpression expressionForVariable:@"zoomLevel"]; } -+ (NSExpression *)mgl_heatmapVariableExpression { ++ (NSExpression *)mgl_heatmapDensityVariableExpression { return [NSExpression expressionForVariable:@"heatmapDensity"]; } @@ -589,6 +589,42 @@ + (NSExpression *)mgl_featurePropertiesVariableExpression { @end +@implementation NSExpression (MGLInitializerAdditions) + ++ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression { + if (@available(iOS 9.0, *)) { + return [NSExpression expressionForConditional:conditionPredicate trueExpression:trueExpression falseExpression:falseExpression]; + } else { + return [NSExpression expressionForFunction:@"MGL_IF" arguments:@[[NSExpression expressionWithFormat:@"%@", conditionPredicate], trueExpression, falseExpression]]; + } +} + ++ (instancetype)mgl_expressionForStepFunction:(NSExpression *)input from:(NSExpression *)from stops:(nonnull NSExpression *)stops { + return [NSExpression expressionForFunction:@"mgl_step:from:stops:" + arguments:@[input, from, stops]]; +} + ++ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)input curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps { + NSExpression *sanitizeParams = parameters ? parameters : [NSExpression expressionForConstantValue:nil]; + return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" + arguments:@[input, [NSExpression expressionForConstantValue:curveType], sanitizeParams, steps]]; +} + ++ (instancetype)mgl_expressionForMatchFunction:(nonnull NSExpression*)condition values:(nonnull NSExpression *)values defaultValue:(nonnull NSExpression *)defaultValue { + NSMutableArray *optionsArray = [NSMutableArray arrayWithArray:values.constantValue]; + [optionsArray insertObject:condition atIndex:0]; + [optionsArray addObject:defaultValue]; + return [NSExpression expressionForFunction:@"MGL_MATCH" + arguments:optionsArray]; +} + +- (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)expression { + NSExpression *subexpression = [NSExpression expressionForAggregate:@[self, expression]]; + return [NSExpression expressionForFunction:@"mgl_join:" arguments:@[subexpression]]; +} + +@end + @implementation NSExpression (MGLExpressionAdditions) - (NSExpression *)mgl_expressionWithContext:(NSDictionary *)context { @@ -619,25 +655,6 @@ @implementation NSExpression (MGLAdditions) return subexpressions; } -+ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression { - if (@available(iOS 9.0, *)) { - return [NSExpression expressionForConditional:conditionPredicate trueExpression:trueExpression falseExpression:falseExpression]; - } else { - return [NSExpression expressionForFunction:@"MGL_IF" arguments:@[[NSExpression expressionWithFormat:@"%@", conditionPredicate], trueExpression, falseExpression]]; - } -} - -+ (instancetype)mgl_expressionForStepFunction:(NSExpression *)operatorExpression defaultExpression:(NSExpression *)expression stops:(nonnull NSExpression *)stops { - return [NSExpression expressionForFunction:@"mgl_step:from:stops:" - arguments:@[operatorExpression, expression, stops]]; -} - -+ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)expressionOperator curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps { - NSExpression *sanitizeParams = parameters ? parameters : [NSExpression expressionForConstantValue:nil]; - return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" - arguments:@[expressionOperator, [NSExpression expressionForConstantValue:curveType], sanitizeParams, steps]]; -} - + (instancetype)expressionWithMGLJSONObject:(id)object { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ @@ -816,7 +833,7 @@ + (instancetype)expressionWithMGLJSONObject:(id)object { } else if ([op isEqualToString:@"zoom"]) { return NSExpression.mgl_zoomLevelVariableExpression; } else if ([op isEqualToString:@"heatmap-density"]) { - return NSExpression.mgl_heatmapVariableExpression; + return NSExpression.mgl_heatmapDensityVariableExpression; } else if ([op isEqualToString:@"geometry-type"]) { return NSExpression.mgl_geometryTypeVariableExpression; } else if ([op isEqualToString:@"id"]) { @@ -873,10 +890,6 @@ + (instancetype)expressionWithMGLJSONObject:(id)object { return nil; } - -- (instancetype)mgl_appendingString:(NSString *)string { - return [self mgl_appendingExpression:[NSExpression mgl_expressionForString:string]]; -} - (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)expression { return [NSExpression expressionForFunction:self selectorName:@"stringByAppendingString:" arguments:@[expression]]; } diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index c91cf36d1a2..2c0fc331dfa 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -1006,4 +1006,54 @@ - (void)testLocalization { } } +- (void)testConvenienceInitializers { + { + NSExpression *expression = [NSExpression mgl_expressionForConditional:[NSPredicate predicateWithFormat:@"1 = 2"] + trueExpression:MGLConstantExpression(@YES) + falseExpresssion:MGLConstantExpression(@NO)]; + + NSArray *jsonExpression = @[@"case", @[@"==", @1, @2], @YES, @NO]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @NO); + } + { + NSDictionary *stops = @{@0: MGLConstantExpression(@111), @1: MGLConstantExpression(@1111)}; + NSExpression *expression = [NSExpression mgl_expressionForStepFunction:[NSExpression expressionForKeyPath:@"x"] + from:[NSExpression expressionForConstantValue:@11] + stops:[NSExpression expressionForConstantValue:stops]]; + NSArray *jsonExpression = @[@"step", @[@"get", @"x"], @11, @0, @111, @1, @1111]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + NSDictionary *stops = @{@0: MGLConstantExpression(@100), @10: MGLConstantExpression(@200)}; + NSExpression *expression = [NSExpression mgl_expressionForInterpolateFunction:[NSExpression expressionForKeyPath:@"x"] + curveType:MGLExpressionInterpolationModeLinear + parameters:nil + steps:[NSExpression expressionForConstantValue:stops]]; + NSArray *jsonExpression = @[@"interpolate", @[@"linear"], @[@"get", @"x"], @0, @100, @10, @200]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + NSExpression *expression = [[NSExpression expressionForConstantValue:@"Old"] mgl_expressionByAppendingExpression:[NSExpression expressionForConstantValue:@"MacDonald"]]; + + NSArray *jsonExpression = @[@"concat", @"Old", @"MacDonald"]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @"OldMacDonald"); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + NSArray *values = @[MGLConstantExpression(@1), MGLConstantExpression(@"one")]; + NSExpression *expression = [NSExpression mgl_expressionForMatchFunction:[NSExpression expressionWithFormat:@"2 * 1"] + values:[NSExpression expressionForConstantValue:values] + defaultValue:[NSExpression expressionForConstantValue:@"default"]]; + NSArray *jsonExpression = @[@"match", @[@"*", @2, @1], @1, @"one", @"default"]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } +} + + @end From cc93fdd81067b399c2b6865113b3bd20c959cb1e Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Sat, 14 Apr 2018 00:41:11 -0400 Subject: [PATCH 3/9] [ios, macos] Add Swift friendly convenience methods name syntax.. # Conflicts: # platform/darwin/src/NSExpression+MGLAdditions.h --- .../darwin/src/NSExpression+MGLAdditions.h | 22 +++++++++++++------ .../darwin/src/NSExpression+MGLAdditions.mm | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index 033ca63d020..9927296eaeb 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -87,7 +87,7 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio @param trueExpression The expression for conditions equal to true. @param falseExpression The expression for conditions equal to false. */ -+ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression; ++ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression NS_SWIFT_NAME(mgl_conditional(_:trueExpression:falseExpression:)); /** Returns a step function expression specifying the function operator, default expression @@ -97,7 +97,7 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio @param from The expression which could be a constant or function expression. @param stops The stops dictionay must be numeric literals in strictly ascending order. */ -+ (instancetype)mgl_expressionForStepFunction:(nonnull NSExpression*)input from:(nonnull NSExpression *)from stops:(nonnull NSExpression*)stops; ++ (instancetype)mgl_expressionForStepFunction:(nonnull NSExpression*)input from:(nonnull NSExpression *)from stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(mgl_stepFunction(input:from:stops:)); /** Returns an interpolated function expression specifying the function operator, curve type, @@ -110,18 +110,26 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio @param parameters The parameters expression. @param steps The steps expression. */ -+ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)input curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps; ++ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)input curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps NS_SWIFT_NAME(mgl_interpolateFunction(input:curveType:parameters:steps:)); -+ (instancetype)mgl_expressionForMatchFunction:(nonnull NSExpression*)condition values:(nonnull NSExpression *)values defaultValue:(nonnull NSExpression *)defaultValue; +/** + Returns a match function expression specifying the condition, lookup values, + and default value. + + @param condition The expression condition. + @param values The lookup values expression. + @param defaultValue The defaultValue expression to be used in case there is no match. + */ ++ (instancetype)mgl_expressionForMatchFunction:(nonnull NSExpression*)condition values:(nonnull NSExpression *)values defaultValue:(nonnull NSExpression *)defaultValue NS_SWIFT_NAME(mgl_matchFunction(condition:values:defaultValue:)); /** - Returns a string constant expression appending the passed expression. + Returns a constant expression appending the passed expression. - @param string The string to append. + @param expression The expression to append to the receiver. system’s preferred language, if supported, specify `nil`. To use the local language, specify a locale with the identifier `mul`. */ -- (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)string; +- (instancetype)mgl_expressionByAppendingExpression:(nonnull NSExpression *)expression NS_SWIFT_NAME(mgl_appending(_:)); @end diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 1dae31d9fc2..adcf6d9ab89 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -618,7 +618,7 @@ + (instancetype)mgl_expressionForMatchFunction:(nonnull NSExpression*)condition arguments:optionsArray]; } -- (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)expression { +- (instancetype)mgl_expressionByAppendingExpression:(nonnull NSExpression *)expression { NSExpression *subexpression = [NSExpression expressionForAggregate:@[self, expression]]; return [NSExpression expressionForFunction:@"mgl_join:" arguments:@[subexpression]]; } From 0fc83615227d32fadc806ae75647e73d057275b5 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Sat, 14 Apr 2018 00:49:17 -0400 Subject: [PATCH 4/9] [ios, macos] Update runtime styling examples. # Conflicts: # platform/ios/app/MBXViewController.m --- platform/ios/app/MBXViewController.m | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 989b8480555..54f16e452f5 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -971,9 +971,6 @@ - (void)styleWaterLayer curveType:MGLExpressionInterpolationModeLinear parameters:nil steps:[NSExpression expressionForConstantValue:waterColorStops]]; - waterLayer.fillColor = [NSExpression expressionWithFormat: - @"mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)", - waterColorStops]; waterLayer.fillColor = fillColorExpression; NSDictionary *fillAntialiasedStops = @{@11: @YES, @@ -981,9 +978,9 @@ - (void)styleWaterLayer @13: @YES, @14: @NO, @15: @YES}; - waterLayer.fillAntialiased = [NSExpression expressionWithFormat: - @"mgl_step:from:stops:($zoomLevel, false, %@)", - fillAntialiasedStops]; + waterLayer.fillAntialiased = [NSExpression mgl_expressionForStepFunction:NSExpression.mgl_zoomLevelVariableExpression + from:[NSExpression expressionForConstantValue:@NO] + stops:[NSExpression expressionForConstantValue:fillAntialiasedStops]]; } - (void)styleRoadLayer From 809ac96226d67db427bc0cf50812d8434e9276c3 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 16 Apr 2018 17:05:10 -0400 Subject: [PATCH 5/9] [ios, macos] Add NSExpression variable expressions properties. --- .../darwin/src/NSExpression+MGLAdditions.h | 20 ++++++------- .../darwin/src/NSExpression+MGLAdditions.mm | 29 +++++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index 9927296eaeb..86d9cf6f7be 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -41,39 +41,39 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio @interface NSExpression (MGLVariableAdditions) /** - `NSExpression` attribute that corresponds to the + `NSExpression` variable that corresponds to the zoom expression reference in the Mapbox Style Specification. */ -+ (NSExpression *)mgl_zoomLevelVariableExpression; +@property (class, nonatomic, readonly) NSExpression *zoomLevelVariableExpression; /** - `NSExpression` attribute that corresponds to the + `NSExpression` variable that corresponds to the heatmap-density expression reference in the Mapbox Style Specification. */ -+ (NSExpression *)mgl_heatmapDensityVariableExpression; +@property (class, nonatomic, readonly) NSExpression *heatmapDensityVariableExpression; /** - `NSExpression` attribute that corresponds to the + `NSExpression` variable that corresponds to the geometry-type expression reference in the Mapbox Style Specification. */ -+ (NSExpression *)mgl_geometryTypeVariableExpression; +@property (class, nonatomic, readonly) NSExpression *geometryTypeVariableExpression; /** - `NSExpression` attribute that corresponds to the + `NSExpression` variable that corresponds to the id expression reference in the Mapbox Style Specification. */ -+ (NSExpression *)mgl_featureIdentifierVariableExpression; +@property (class, nonatomic, readonly) NSExpression *featureIdentifierVariableExpression; /** - `NSExpression` attribute that corresponds to the + `NSExpression` variable that corresponds to the properties expression reference in the Mapbox Style Specification. */ -+ (NSExpression *)mgl_featurePropertiesVariableExpression; +@property (class, nonatomic, readonly) NSExpression *featurePropertiesVariableExpression; @end diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index adcf6d9ab89..7d35c09b4fa 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -567,24 +567,24 @@ - (id)mgl_has:(id)element { @end @implementation NSExpression (MGLVariableAdditions) -+ (NSExpression *)mgl_zoomLevelVariableExpression { ++ (NSExpression *)zoomLevelVariableExpression { return [NSExpression expressionForVariable:@"zoomLevel"]; } -+ (NSExpression *)mgl_heatmapDensityVariableExpression { ++ (NSExpression *)heatmapDensityVariableExpression { return [NSExpression expressionForVariable:@"heatmapDensity"]; } -+ (NSExpression *)mgl_geometryTypeVariableExpression { - return [NSExpression expressionForVariable:@"mgl_geometryType"]; ++ (NSExpression *)geometryTypeVariableExpression { + return [NSExpression expressionForVariable:@"geometryType"]; } -+ (NSExpression *)mgl_featureIdentifierVariableExpression { - return [NSExpression expressionForVariable:@"mgl_featureIdentifier"]; ++ (NSExpression *)featureIdentifierVariableExpression { + return [NSExpression expressionForVariable:@"featureIdentifier"]; } -+ (NSExpression *)mgl_featurePropertiesVariableExpression { - return [NSExpression expressionForVariable:@"mgl_featureProperties"]; ++ (NSExpression *)featurePropertiesVariableExpression { + return [NSExpression expressionForVariable:@"featureProperties"]; } @end @@ -831,15 +831,15 @@ + (instancetype)expressionWithMGLJSONObject:(id)object { return [NSExpression expressionForFunction:@"mgl_step:from:stops:" arguments:@[inputExpression, minimum, stopExpression]]; } else if ([op isEqualToString:@"zoom"]) { - return NSExpression.mgl_zoomLevelVariableExpression; + return NSExpression.zoomLevelVariableExpression; } else if ([op isEqualToString:@"heatmap-density"]) { - return NSExpression.mgl_heatmapDensityVariableExpression; + return NSExpression.heatmapDensityVariableExpression; } else if ([op isEqualToString:@"geometry-type"]) { - return NSExpression.mgl_geometryTypeVariableExpression; + return NSExpression.geometryTypeVariableExpression; } else if ([op isEqualToString:@"id"]) { - return NSExpression.mgl_featureIdentifierVariableExpression; + return NSExpression.featureIdentifierVariableExpression; } else if ([op isEqualToString:@"properties"]) { - return NSExpression.mgl_featurePropertiesVariableExpression; + return NSExpression.featurePropertiesVariableExpression; } else if ([op isEqualToString:@"var"]) { return [NSExpression expressionForVariable:argumentObjects.firstObject]; } else if ([op isEqualToString:@"case"]) { @@ -890,9 +890,6 @@ + (instancetype)expressionWithMGLJSONObject:(id)object { return nil; } -- (instancetype)mgl_expressionByAppendingExpression:(NSExpression *)expression { - return [NSExpression expressionForFunction:self selectorName:@"stringByAppendingString:" arguments:@[expression]]; -} - (id)mgl_jsonExpressionObject { static dispatch_once_t onceToken; From 329d873b1752ae3eaad98db208ee4d220bf7448d Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 16 Apr 2018 18:36:25 -0400 Subject: [PATCH 6/9] [ios, macos] Clarify convenience initializer names. --- .../darwin/src/NSExpression+MGLAdditions.h | 33 ++++++++++--------- .../darwin/src/NSExpression+MGLAdditions.mm | 22 ++++++++----- platform/darwin/test/MGLExpressionTests.mm | 22 ++++++------- platform/ios/app/MBXViewController.m | 14 ++++---- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index 86d9cf6f7be..39f410c7a48 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -87,44 +87,47 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio @param trueExpression The expression for conditions equal to true. @param falseExpression The expression for conditions equal to false. */ -+ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression NS_SWIFT_NAME(mgl_conditional(_:trueExpression:falseExpression:)); ++ (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPredicate trueExpression:(nonnull NSExpression *)trueExpression falseExpresssion:(nonnull NSExpression *)falseExpression NS_SWIFT_NAME(init(forMGLConditional:trueExpression:falseExpression:)); /** - Returns a step function expression specifying the function operator, default expression + Returns a step function expression specifying the stepping, from expression and stops. - @param input The input expression. - @param from The expression which could be a constant or function expression. - @param stops The stops dictionay must be numeric literals in strictly ascending order. + @param steppingExpression The stepping expression. + @param fromExpression The expression which could be a constant or function expression. + @param stops The stops must be an `NSDictionary` constant `NSExpression`. + The wrapped dictionary must be numeric expression literals in strictly ascending order. */ -+ (instancetype)mgl_expressionForStepFunction:(nonnull NSExpression*)input from:(nonnull NSExpression *)from stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(mgl_stepFunction(input:from:stops:)); ++ (instancetype)mgl_expressionForSteppingExpression:(nonnull NSExpression*)steppingExpression fromExpression:(nonnull NSExpression *)fromExpression stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(init(forMGLStepping:from:stops:)); /** Returns an interpolated function expression specifying the function operator, curve type, parameters and steps. - @param input The expression input. + @param interpolatingExpression The interpolating expression input. @param curveType The curve type could be `MGLExpressionInterpolationModeLinear`, `MGLExpressionInterpolationModeExponential` and `MGLExpressionInterpolationModeCubicBezier`. @param parameters The parameters expression. - @param steps The steps expression. + @param stops The stops expression. */ -+ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)input curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps NS_SWIFT_NAME(mgl_interpolateFunction(input:curveType:parameters:steps:)); ++ (instancetype)mgl_expressionForInterpolatingExpression:(nonnull NSExpression*)interpolatingExpression withCurveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(init(forMGLInterpolating:curveType:parameters:stops:)); /** - Returns a match function expression specifying the condition, lookup values, + Returns a match function expression specifying the input, matching values, and default value. - @param condition The expression condition. - @param values The lookup values expression. - @param defaultValue The defaultValue expression to be used in case there is no match. + @param matchingExpression The matching expression. + @param matchedExpressions The matched values expression dictionary must be condition : value. + @param defaultExpression The defaultValue expression to be used in case there is no match. */ -+ (instancetype)mgl_expressionForMatchFunction:(nonnull NSExpression*)condition values:(nonnull NSExpression *)values defaultValue:(nonnull NSExpression *)defaultValue NS_SWIFT_NAME(mgl_matchFunction(condition:values:defaultValue:)); - ++ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)matchingExpression inDictionary:(nonnull NSDictionary *)matchedExpressions defaultExpression:(nonnull NSExpression *)defaultExpression NS_SWIFT_NAME(init(forMGLMatchingKey:matched:default:)); /** Returns a constant expression appending the passed expression. + @note Both the receiver and the given expression must be an `NSString` constant + expression type; otherwise, an exception is rised. + @param expression The expression to append to the receiver. system’s preferred language, if supported, specify `nil`. To use the local language, specify a locale with the identifier `mul`. diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 7d35c09b4fa..956e8504509 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -599,21 +599,27 @@ + (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPre } } -+ (instancetype)mgl_expressionForStepFunction:(NSExpression *)input from:(NSExpression *)from stops:(nonnull NSExpression *)stops { ++ (instancetype)mgl_expressionForSteppingExpression:(nonnull NSExpression*)steppingExpression fromExpression:(nonnull NSExpression *)fromExpression stops:(nonnull NSExpression*)stops { return [NSExpression expressionForFunction:@"mgl_step:from:stops:" - arguments:@[input, from, stops]]; + arguments:@[steppingExpression, fromExpression, stops]]; } -+ (instancetype)mgl_expressionForInterpolateFunction:(nonnull NSExpression*)input curveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters steps:(nonnull NSExpression*)steps { ++ (instancetype)mgl_expressionForInterpolatingExpression:(nonnull NSExpression*)interpolatingExpression withCurveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters stops:(nonnull NSExpression*)stops { NSExpression *sanitizeParams = parameters ? parameters : [NSExpression expressionForConstantValue:nil]; return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" - arguments:@[input, [NSExpression expressionForConstantValue:curveType], sanitizeParams, steps]]; + arguments:@[interpolatingExpression, [NSExpression expressionForConstantValue:curveType], sanitizeParams, stops]]; } -+ (instancetype)mgl_expressionForMatchFunction:(nonnull NSExpression*)condition values:(nonnull NSExpression *)values defaultValue:(nonnull NSExpression *)defaultValue { - NSMutableArray *optionsArray = [NSMutableArray arrayWithArray:values.constantValue]; - [optionsArray insertObject:condition atIndex:0]; - [optionsArray addObject:defaultValue]; ++ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)matchingExpression inDictionary:(nonnull NSDictionary *)matchedExpressions defaultExpression:(nonnull NSExpression *)defaultExpression { + NSMutableArray *optionsArray = [NSMutableArray arrayWithObjects:matchingExpression, nil]; + + NSEnumerator *matchEnumerator = matchedExpressions.keyEnumerator; + while (NSExpression *key = matchEnumerator.nextObject) { + [optionsArray addObject:key]; + [optionsArray addObject:[matchedExpressions objectForKey:key]]; + } + + [optionsArray addObject:defaultExpression]; return [NSExpression expressionForFunction:@"MGL_MATCH" arguments:optionsArray]; } diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 2c0fc331dfa..e078c4f4b62 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -1019,19 +1019,19 @@ - (void)testConvenienceInitializers { } { NSDictionary *stops = @{@0: MGLConstantExpression(@111), @1: MGLConstantExpression(@1111)}; - NSExpression *expression = [NSExpression mgl_expressionForStepFunction:[NSExpression expressionForKeyPath:@"x"] - from:[NSExpression expressionForConstantValue:@11] - stops:[NSExpression expressionForConstantValue:stops]]; + NSExpression *expression = [NSExpression mgl_expressionForSteppingExpression:[NSExpression expressionForKeyPath:@"x"] + fromExpression:[NSExpression expressionForConstantValue:@11] + stops:[NSExpression expressionForConstantValue:stops]]; NSArray *jsonExpression = @[@"step", @[@"get", @"x"], @11, @0, @111, @1, @1111]; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } { NSDictionary *stops = @{@0: MGLConstantExpression(@100), @10: MGLConstantExpression(@200)}; - NSExpression *expression = [NSExpression mgl_expressionForInterpolateFunction:[NSExpression expressionForKeyPath:@"x"] - curveType:MGLExpressionInterpolationModeLinear - parameters:nil - steps:[NSExpression expressionForConstantValue:stops]]; + NSExpression *expression = [NSExpression mgl_expressionForInterpolatingExpression:[NSExpression expressionForKeyPath:@"x"] + withCurveType:MGLExpressionInterpolationModeLinear + parameters:nil + stops:[NSExpression expressionForConstantValue:stops]]; NSArray *jsonExpression = @[@"interpolate", @[@"linear"], @[@"get", @"x"], @0, @100, @10, @200]; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); @@ -1045,10 +1045,10 @@ - (void)testConvenienceInitializers { XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } { - NSArray *values = @[MGLConstantExpression(@1), MGLConstantExpression(@"one")]; - NSExpression *expression = [NSExpression mgl_expressionForMatchFunction:[NSExpression expressionWithFormat:@"2 * 1"] - values:[NSExpression expressionForConstantValue:values] - defaultValue:[NSExpression expressionForConstantValue:@"default"]]; + NSDictionary *values = @{ MGLConstantExpression(@1): MGLConstantExpression(@"one") }; + NSExpression *expression = [NSExpression mgl_expressionForMatchingExpression:[NSExpression expressionWithFormat:@"2 * 1"] + inDictionary:values + defaultExpression:[NSExpression expressionForConstantValue:@"default"]]; NSArray *jsonExpression = @[@"match", @[@"*", @2, @1], @1, @"one", @"default"]; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 54f16e452f5..391af5ea052 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -967,10 +967,10 @@ - (void)styleWaterLayer @10.0f: [UIColor redColor], @12.0f: [UIColor greenColor], @14.0f: [UIColor blueColor]}; - NSExpression *fillColorExpression = [NSExpression mgl_expressionForInterpolateFunction:NSExpression.mgl_zoomLevelVariableExpression - curveType:MGLExpressionInterpolationModeLinear - parameters:nil - steps:[NSExpression expressionForConstantValue:waterColorStops]]; + NSExpression *fillColorExpression = [NSExpression mgl_expressionForInterpolatingExpression:NSExpression.zoomLevelVariableExpression + withCurveType:MGLExpressionInterpolationModeLinear + parameters:nil + stops:[NSExpression expressionForConstantValue:waterColorStops]]; waterLayer.fillColor = fillColorExpression; NSDictionary *fillAntialiasedStops = @{@11: @YES, @@ -978,9 +978,9 @@ - (void)styleWaterLayer @13: @YES, @14: @NO, @15: @YES}; - waterLayer.fillAntialiased = [NSExpression mgl_expressionForStepFunction:NSExpression.mgl_zoomLevelVariableExpression - from:[NSExpression expressionForConstantValue:@NO] - stops:[NSExpression expressionForConstantValue:fillAntialiasedStops]]; + waterLayer.fillAntialiased = [NSExpression mgl_expressionForSteppingExpression:NSExpression.zoomLevelVariableExpression + fromExpression:[NSExpression expressionForConstantValue:@NO] + stops:[NSExpression expressionForConstantValue:fillAntialiasedStops]]; } - (void)styleRoadLayer From 6c8316a8b36dcb868b80f594d2cb80bb53fbfb2c Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 16 Apr 2018 18:51:47 -0400 Subject: [PATCH 7/9] [ios, macos] Update Style Authors guides. --- .../docs/guides/For Style Authors.md.ejs | 20 +++++++++---------- platform/ios/docs/guides/For Style Authors.md | 20 +++++++++---------- .../macos/docs/guides/For Style Authors.md | 20 +++++++++---------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/platform/darwin/docs/guides/For Style Authors.md.ejs b/platform/darwin/docs/guides/For Style Authors.md.ejs index 4fa70ff8076..a3083571cfa 100644 --- a/platform/darwin/docs/guides/For Style Authors.md.ejs +++ b/platform/darwin/docs/guides/For Style Authors.md.ejs @@ -339,9 +339,9 @@ In style specification | Method, function, or predicate type | Format string syn `to-number` | `mgl_numberWithFallbackValues:` | `CAST(zipCode, 'NSNumber')` `to-string` | `stringValue` | `CAST(ele, 'NSString')` `typeof` | | -`geometry-type` | |`$geometryType` -`id` | |`$featureIdentifier` -`properties` | |`$featureProperties` +`geometry-type` | `NSExpression.geometryTypeVariableExpression` | `$geometryType` +`id` | `NSExpression.featureIdentifierVariableExpression` | `$featureIdentifier` +`properties` | `NSExpression.featurePropertiesVariableExpression` | `$featureProperties` `at` | `objectFrom:withIndex:` | `array[n]` `get` | `+[NSExpression expressionForKeyPath:]` | Key path `has` | `mgl_does:have:` | `mgl_does:have:(self, 'key')` @@ -355,14 +355,14 @@ In style specification | Method, function, or predicate type | Format string syn `>=` | `NSGreaterThanOrEqualToPredicateOperatorType` | `key >= value` `all` | `NSAndPredicateType` | `p0 AND … AND pn` `any` | `NSOrPredicateType` | `p0 OR … OR pn` -`case` | `+[NSExpression expressionForConditional:trueExpression:falseExpression:]` or `MGL_IF` | `TERNARY(1 = 2, YES, NO)` or `MGL_IF(1 = 2, YES, 2 = 2, YES, NO)` +`case` | `+[NSExpression expressionForConditional:trueExpression:falseExpression:]` or `MGL_IF` or `+[NSExpression mgl_expressionForConditional:trueExpression:falseExpresssion:]` | `TERNARY(1 = 2, YES, NO)` or `MGL_IF(1 = 2, YES, 2 = 2, YES, NO)` `coalesce` | `mgl_coalesce:` | `mgl_coalesce({x, y, z})` -`match` | `MGL_MATCH` | `MGL_MATCH(x, 0, 'zero match', 1, 'one match', 'two match', 'default')` -`interpolate` | `mgl_interpolate:withCurveType:parameters:stops:` | -`step` | `mgl_step:withMinimum:stops:` | +`match` | `MGL_MATCH` or `+[NSExpression mgl_expressionForMatchingExpression:inDictionary:defaultExpression:]` | `MGL_MATCH(x, 0, 'zero match', 1, 'one match', 'two match', 'default')` +`interpolate` | `mgl_interpolate:withCurveType:parameters:stops:` or `+[NSExpression mgl_expressionForInterpolatingExpression:withCurveType:parameters:stops:]` | +`step` | `mgl_step:withMinimum:stops:` or `+[NSExpression mgl_expressionForSteppingExpression:fromExpression:stops:]` | `let` | `mgl_expressionWithContext:` | `MGL_LET('ios', 11, 'macos', 10.13, $ios + $macos)` `var` | `+[NSExpression expressionForVariable:]` | `$variable` -`concat` | `mgl_join:` | `mgl_join({'Old', ' ', 'MacDonald'})` +`concat` | `mgl_join:` or `-[NSExpression mgl_expressionByAppendingExpression:]` | `mgl_join({'Old', ' ', 'MacDonald'})` `downcase` | `lowercase:` | `lowercase('DOWNTOWN')` `upcase` | `uppercase:` | `uppercase('Elysian Fields')` <% if (macOS) { -%> @@ -398,8 +398,8 @@ In style specification | Method, function, or predicate type | Format string syn `sin` | | `sqrt` | `sqrt:` | `sqrt(2)` `tan` | | -`zoom` | | `$zoom` -`heatmap-density` | | `$heatmapDensity` +`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoom` +`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity` For operators that have no corresponding `NSExpression` symbol, use the `MGL_FUNCTION()` format string syntax. diff --git a/platform/ios/docs/guides/For Style Authors.md b/platform/ios/docs/guides/For Style Authors.md index 852a9c2ef40..1ce0a4bf4f9 100644 --- a/platform/ios/docs/guides/For Style Authors.md +++ b/platform/ios/docs/guides/For Style Authors.md @@ -329,9 +329,9 @@ In style specification | Method, function, or predicate type | Format string syn `to-number` | `mgl_numberWithFallbackValues:` | `CAST(zipCode, 'NSNumber')` `to-string` | `stringValue` | `CAST(ele, 'NSString')` `typeof` | | -`geometry-type` | |`$geometryType` -`id` | |`$featureIdentifier` -`properties` | |`$featureProperties` +`geometry-type` | `NSExpression.geometryTypeVariableExpression` | `$geometryType` +`id` | `NSExpression.featureIdentifierVariableExpression` | `$featureIdentifier` +`properties` | `NSExpression.featurePropertiesVariableExpression` | `$featureProperties` `at` | `objectFrom:withIndex:` | `array[n]` `get` | `+[NSExpression expressionForKeyPath:]` | Key path `has` | `mgl_does:have:` | `mgl_does:have:(self, 'key')` @@ -345,14 +345,14 @@ In style specification | Method, function, or predicate type | Format string syn `>=` | `NSGreaterThanOrEqualToPredicateOperatorType` | `key >= value` `all` | `NSAndPredicateType` | `p0 AND … AND pn` `any` | `NSOrPredicateType` | `p0 OR … OR pn` -`case` | `+[NSExpression expressionForConditional:trueExpression:falseExpression:]` or `MGL_IF` | `TERNARY(1 = 2, YES, NO)` or `MGL_IF(1 = 2, YES, 2 = 2, YES, NO)` +`case` | `+[NSExpression expressionForConditional:trueExpression:falseExpression:]` or `MGL_IF` or `+[NSExpression mgl_expressionForConditional:trueExpression:falseExpresssion:]` | `TERNARY(1 = 2, YES, NO)` or `MGL_IF(1 = 2, YES, 2 = 2, YES, NO)` `coalesce` | `mgl_coalesce:` | `mgl_coalesce({x, y, z})` -`match` | `MGL_MATCH` | `MGL_MATCH(x, 0, 'zero match', 1, 'one match', 'two match', 'default')` -`interpolate` | `mgl_interpolate:withCurveType:parameters:stops:` | -`step` | `mgl_step:withMinimum:stops:` | +`match` | `MGL_MATCH` or `+[NSExpression mgl_expressionForMatchingExpression:inDictionary:defaultExpression:]` | `MGL_MATCH(x, 0, 'zero match', 1, 'one match', 'two match', 'default')` +`interpolate` | `mgl_interpolate:withCurveType:parameters:stops:` or `+[NSExpression mgl_expressionForInterpolatingExpression:withCurveType:parameters:stops:]` | +`step` | `mgl_step:withMinimum:stops:` or `+[NSExpression mgl_expressionForSteppingExpression:fromExpression:stops:]` | `let` | `mgl_expressionWithContext:` | `MGL_LET('ios', 11, 'macos', 10.13, $ios + $macos)` `var` | `+[NSExpression expressionForVariable:]` | `$variable` -`concat` | `mgl_join:` | `mgl_join({'Old', ' ', 'MacDonald'})` +`concat` | `mgl_join:` or `-[NSExpression mgl_expressionByAppendingExpression:]` | `mgl_join({'Old', ' ', 'MacDonald'})` `downcase` | `lowercase:` | `lowercase('DOWNTOWN')` `upcase` | `uppercase:` | `uppercase('Elysian Fields')` `rgb` | `+[UIColor colorWithRed:green:blue:alpha:]` | @@ -383,8 +383,8 @@ In style specification | Method, function, or predicate type | Format string syn `sin` | | `sqrt` | `sqrt:` | `sqrt(2)` `tan` | | -`zoom` | | `$zoom` -`heatmap-density` | | `$heatmapDensity` +`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoom` +`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity` For operators that have no corresponding `NSExpression` symbol, use the `MGL_FUNCTION()` format string syntax. diff --git a/platform/macos/docs/guides/For Style Authors.md b/platform/macos/docs/guides/For Style Authors.md index dea4eb845a4..c8e517a5bd9 100644 --- a/platform/macos/docs/guides/For Style Authors.md +++ b/platform/macos/docs/guides/For Style Authors.md @@ -322,9 +322,9 @@ In style specification | Method, function, or predicate type | Format string syn `to-number` | `mgl_numberWithFallbackValues:` | `CAST(zipCode, 'NSNumber')` `to-string` | `stringValue` | `CAST(ele, 'NSString')` `typeof` | | -`geometry-type` | |`$geometryType` -`id` | |`$featureIdentifier` -`properties` | |`$featureProperties` +`geometry-type` | `NSExpression.geometryTypeVariableExpression` | `$geometryType` +`id` | `NSExpression.featureIdentifierVariableExpression` | `$featureIdentifier` +`properties` | `NSExpression.featurePropertiesVariableExpression` | `$featureProperties` `at` | `objectFrom:withIndex:` | `array[n]` `get` | `+[NSExpression expressionForKeyPath:]` | Key path `has` | `mgl_does:have:` | `mgl_does:have:(self, 'key')` @@ -338,14 +338,14 @@ In style specification | Method, function, or predicate type | Format string syn `>=` | `NSGreaterThanOrEqualToPredicateOperatorType` | `key >= value` `all` | `NSAndPredicateType` | `p0 AND … AND pn` `any` | `NSOrPredicateType` | `p0 OR … OR pn` -`case` | `+[NSExpression expressionForConditional:trueExpression:falseExpression:]` or `MGL_IF` | `TERNARY(1 = 2, YES, NO)` or `MGL_IF(1 = 2, YES, 2 = 2, YES, NO)` +`case` | `+[NSExpression expressionForConditional:trueExpression:falseExpression:]` or `MGL_IF` or `+[NSExpression mgl_expressionForConditional:trueExpression:falseExpresssion:]` | `TERNARY(1 = 2, YES, NO)` or `MGL_IF(1 = 2, YES, 2 = 2, YES, NO)` `coalesce` | `mgl_coalesce:` | `mgl_coalesce({x, y, z})` -`match` | `MGL_MATCH` | `MGL_MATCH(x, 0, 'zero match', 1, 'one match', 'two match', 'default')` -`interpolate` | `mgl_interpolate:withCurveType:parameters:stops:` | -`step` | `mgl_step:withMinimum:stops:` | +`match` | `MGL_MATCH` or `+[NSExpression mgl_expressionForMatchingExpression:inDictionary:defaultExpression:]` | `MGL_MATCH(x, 0, 'zero match', 1, 'one match', 'two match', 'default')` +`interpolate` | `mgl_interpolate:withCurveType:parameters:stops:` or `+[NSExpression mgl_expressionForInterpolatingExpression:withCurveType:parameters:stops:]` | +`step` | `mgl_step:withMinimum:stops:` or `+[NSExpression mgl_expressionForSteppingExpression:fromExpression:stops:]` | `let` | `mgl_expressionWithContext:` | `MGL_LET('ios', 11, 'macos', 10.13, $ios + $macos)` `var` | `+[NSExpression expressionForVariable:]` | `$variable` -`concat` | `mgl_join:` | `mgl_join({'Old', ' ', 'MacDonald'})` +`concat` | `mgl_join:` or `-[NSExpression mgl_expressionByAppendingExpression:]` | `mgl_join({'Old', ' ', 'MacDonald'})` `downcase` | `lowercase:` | `lowercase('DOWNTOWN')` `upcase` | `uppercase:` | `uppercase('Elysian Fields')` `rgb` | `+[NSColor colorWithCalibratedRed:green:blue:alpha:]` | @@ -376,8 +376,8 @@ In style specification | Method, function, or predicate type | Format string syn `sin` | | `sqrt` | `sqrt:` | `sqrt(2)` `tan` | | -`zoom` | | `$zoom` -`heatmap-density` | | `$heatmapDensity` +`zoom` | `NSExpression.zoomLevelVariableExpression` | `$zoom` +`heatmap-density` | `NSExpression.heatmapDensityVariableExpression` | `$heatmapDensity` For operators that have no corresponding `NSExpression` symbol, use the `MGL_FUNCTION()` format string syntax. From 417eee0b1b9630c75478edd6158f8198f7d751b2 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 16 Apr 2018 19:35:51 -0400 Subject: [PATCH 8/9] [ios, macos] Fix cherry-pick merge. --- platform/darwin/src/NSExpression+MGLAdditions.h | 1 - 1 file changed, 1 deletion(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index 39f410c7a48..018145cf35c 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -166,7 +166,6 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio guide for a correspondence of operators and types between the style specification and the `NSExpression` representation used by this SDK. - @param locale The locale into which labels should be localized. To use the You can use `NSJSONSerialization` to serialize the Foundation object as data to write to a file. */ From e78372e81cf0526aa691631df64f056c64dee572 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Mon, 16 Apr 2018 20:27:29 -0400 Subject: [PATCH 9/9] [ios, macos] Update convenience initializers documentation. --- platform/darwin/src/NSExpression+MGLAdditions.h | 17 +++++++---------- .../darwin/src/NSExpression+MGLAdditions.mm | 12 ++++++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index 018145cf35c..39a841543d4 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN -typedef NSString *MGLExpressionInterpolationMode NS_TYPED_EXTENSIBLE_ENUM; +typedef NSString *MGLExpressionInterpolationMode NS_TYPED_ENUM; /** An `NSString` identifying the `linear` interpolation type in an `NSExpression`. @@ -94,34 +94,33 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio and stops. @param steppingExpression The stepping expression. - @param fromExpression The expression which could be a constant or function expression. + @param minimumExpression The expression which could be a constant or function expression. @param stops The stops must be an `NSDictionary` constant `NSExpression`. - The wrapped dictionary must be numeric expression literals in strictly ascending order. */ -+ (instancetype)mgl_expressionForSteppingExpression:(nonnull NSExpression*)steppingExpression fromExpression:(nonnull NSExpression *)fromExpression stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(init(forMGLStepping:from:stops:)); ++ (instancetype)mgl_expressionForSteppingExpression:(nonnull NSExpression*)steppingExpression fromExpression:(nonnull NSExpression *)minimumExpression stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(init(forMGLStepping:from:stops:)); /** Returns an interpolated function expression specifying the function operator, curve type, parameters and steps. - @param interpolatingExpression The interpolating expression input. + @param inputExpression The interpolating expression input. @param curveType The curve type could be `MGLExpressionInterpolationModeLinear`, `MGLExpressionInterpolationModeExponential` and `MGLExpressionInterpolationModeCubicBezier`. @param parameters The parameters expression. @param stops The stops expression. */ -+ (instancetype)mgl_expressionForInterpolatingExpression:(nonnull NSExpression*)interpolatingExpression withCurveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(init(forMGLInterpolating:curveType:parameters:stops:)); ++ (instancetype)mgl_expressionForInterpolatingExpression:(nonnull NSExpression*)inputExpression withCurveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters stops:(nonnull NSExpression*)stops NS_SWIFT_NAME(init(forMGLInterpolating:curveType:parameters:stops:)); /** Returns a match function expression specifying the input, matching values, and default value. - @param matchingExpression The matching expression. + @param inputExpression The matching expression. @param matchedExpressions The matched values expression dictionary must be condition : value. @param defaultExpression The defaultValue expression to be used in case there is no match. */ -+ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)matchingExpression inDictionary:(nonnull NSDictionary *)matchedExpressions defaultExpression:(nonnull NSExpression *)defaultExpression NS_SWIFT_NAME(init(forMGLMatchingKey:matched:default:)); ++ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)inputExpression inDictionary:(nonnull NSDictionary *)matchedExpressions defaultExpression:(nonnull NSExpression *)defaultExpression NS_SWIFT_NAME(init(forMGLMatchingKey:in:default:)); /** Returns a constant expression appending the passed expression. @@ -129,8 +128,6 @@ extern MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionInterpolatio expression type; otherwise, an exception is rised. @param expression The expression to append to the receiver. - system’s preferred language, if supported, specify `nil`. To use the local - language, specify a locale with the identifier `mul`. */ - (instancetype)mgl_expressionByAppendingExpression:(nonnull NSExpression *)expression NS_SWIFT_NAME(mgl_appending(_:)); diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 956e8504509..54f98c6ab92 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -599,19 +599,19 @@ + (instancetype)mgl_expressionForConditional:(nonnull NSPredicate *)conditionPre } } -+ (instancetype)mgl_expressionForSteppingExpression:(nonnull NSExpression*)steppingExpression fromExpression:(nonnull NSExpression *)fromExpression stops:(nonnull NSExpression*)stops { ++ (instancetype)mgl_expressionForSteppingExpression:(nonnull NSExpression*)steppingExpression fromExpression:(nonnull NSExpression *)minimumExpression stops:(nonnull NSExpression*)stops { return [NSExpression expressionForFunction:@"mgl_step:from:stops:" - arguments:@[steppingExpression, fromExpression, stops]]; + arguments:@[steppingExpression, minimumExpression, stops]]; } -+ (instancetype)mgl_expressionForInterpolatingExpression:(nonnull NSExpression*)interpolatingExpression withCurveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters stops:(nonnull NSExpression*)stops { ++ (instancetype)mgl_expressionForInterpolatingExpression:(nonnull NSExpression*)inputExpression withCurveType:(nonnull MGLExpressionInterpolationMode)curveType parameters:(nullable NSExpression *)parameters stops:(nonnull NSExpression*)stops { NSExpression *sanitizeParams = parameters ? parameters : [NSExpression expressionForConstantValue:nil]; return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" - arguments:@[interpolatingExpression, [NSExpression expressionForConstantValue:curveType], sanitizeParams, stops]]; + arguments:@[inputExpression, [NSExpression expressionForConstantValue:curveType], sanitizeParams, stops]]; } -+ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)matchingExpression inDictionary:(nonnull NSDictionary *)matchedExpressions defaultExpression:(nonnull NSExpression *)defaultExpression { - NSMutableArray *optionsArray = [NSMutableArray arrayWithObjects:matchingExpression, nil]; ++ (instancetype)mgl_expressionForMatchingExpression:(nonnull NSExpression *)inputExpression inDictionary:(nonnull NSDictionary *)matchedExpressions defaultExpression:(nonnull NSExpression *)defaultExpression { + NSMutableArray *optionsArray = [NSMutableArray arrayWithObjects:inputExpression, nil]; NSEnumerator *matchEnumerator = matchedExpressions.keyEnumerator; while (NSExpression *key = matchEnumerator.nextObject) {