diff --git a/platform/darwin/src/NSExpression+MLNAdditions.mm b/platform/darwin/src/NSExpression+MLNAdditions.mm index 20b5e10ef..263dd1c5b 100644 --- a/platform/darwin/src/NSExpression+MLNAdditions.mm +++ b/platform/darwin/src/NSExpression+MLNAdditions.mm @@ -1559,7 +1559,7 @@ NSArray *MLNSubexpressionsWithJSONObjects(NSArray *objects) { firstCondition = self.operand; } - if ([firstCondition respondsToSelector:@selector(constantValue)] && + if (firstCondition.expressionType == NSConstantValueExpressionType && [firstCondition.constantValue isKindOfClass:[NSComparisonPredicate class]]) { NSPredicate *predicate = (NSPredicate *)firstCondition.constantValue; condition = predicate.mgl_jsonExpressionObject; @@ -1572,7 +1572,7 @@ NSArray *MLNSubexpressionsWithJSONObjects(NSArray *objects) { isAftermarketFunction ? self.arguments : self.arguments[minimumIndex].constantValue; for (NSUInteger index = minimumIndex; index < arguments.count; index++) { - if ([arguments[index] respondsToSelector:@selector(constantValue)] && + if (arguments[index].expressionType == NSConstantValueExpressionType && [arguments[index].constantValue isKindOfClass:[NSComparisonPredicate class]]) { NSPredicate *predicate = (NSPredicate *)arguments[index].constantValue; [expressionObject addObject:predicate.mgl_jsonExpressionObject]; diff --git a/platform/darwin/test/MLNStyleTests.mm b/platform/darwin/test/MLNStyleTests.mm index 933537c0f..6733222f8 100644 --- a/platform/darwin/test/MLNStyleTests.mm +++ b/platform/darwin/test/MLNStyleTests.mm @@ -318,6 +318,23 @@ NSException, @"MLNRedundantLayerIdentifierException"); } +- (void)testSymbolLayerIconImageNameWithMultiCaseImageExpression { + MLNPointFeature *feature = [[MLNPointFeature alloc] init]; + MLNShapeSource *source = [[MLNShapeSource alloc] initWithIdentifier:@"sourceID" + shape:feature + options:nil]; + MLNSymbolStyleLayer *layer = [[MLNSymbolStyleLayer alloc] initWithIdentifier:@"layerID" + source:source]; + // Reproduces https://github.com/maplibre/maplibre-native/issues/3477. + NSArray *jsonExpression = @[ + @"case", @[ @"==", @[ @"get", @"icon" ], @"1" ], @[ @"image", @"icon1" ], + @[ @"==", @[ @"get", @"icon" ], @"2" ], @[ @"image", @"icon2" ], @[ @"image", @"icon3" ] + ]; + NSExpression *expression = [NSExpression expressionWithMLNJSONObject:jsonExpression]; + + XCTAssertNoThrow(layer.iconImageName = expression); +} + - (void)testRemovingLayerBeforeAddingSameLayer { { MLNShapeSource *source =