From 7e208c46cebe5b49d4b7ead9826bbe4229ebabd3 Mon Sep 17 00:00:00 2001 From: Jesse Bounds Date: Thu, 1 Sep 2016 06:48:36 -0700 Subject: [PATCH] [ios] Check for bool value with char We convert NSNumbers (and NSStrings) to the appropriate mbgl value so that we can use NSPredicates to describe mbgl filters we want to apply to style layers at runtime. This change fixes an issue where the conversion from an NSNumber that represented a bool was not recognized as such. encode(bool) returns a 'c' or 'b' on 32 bit and 64 bit systems respectively and objCType of an NSNumber representing a bool always returns 'c'. Now the implementation checks for 'c' always and NSNumbers representing bool don't fall through and trigger the exception. --- platform/darwin/src/NSExpression+MGLAdditions.mm | 2 +- platform/darwin/test/MGLFilterTests.mm | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 5f1a1e765..129c9a740 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -31,7 +31,7 @@ return { number.intValue }; } else if ((strcmp([number objCType], @encode(double))) == 0) { return { number.doubleValue }; - } else if ((strcmp([number objCType], @encode(bool))) == 0) { + } else if ((strcmp([number objCType], @encode(char))) == 0) { return { number.boolValue }; } } diff --git a/platform/darwin/test/MGLFilterTests.mm b/platform/darwin/test/MGLFilterTests.mm index 04cb82fac..5b102e2e8 100644 --- a/platform/darwin/test/MGLFilterTests.mm +++ b/platform/darwin/test/MGLFilterTests.mm @@ -42,6 +42,7 @@ NSPredicate *typePredicate = [NSPredicate predicateWithFormat:@"%K == %@", @"$type", @"Feature"]; NSPredicate *idPredicate = [NSPredicate predicateWithFormat:@"%K == %@", @"$id", @"1234123"]; NSPredicate *specialCharsPredicate = [NSPredicate predicateWithFormat:@"%K == %@", @"ty-’pè", @"sŒm-ethįng"]; + NSPredicate *booleanPredicate = [NSPredicate predicateWithFormat:@"%K != %@", @"cluster", [NSNumber numberWithBool:YES]]; return @[equalPredicate, notEqualPredicate, greaterThanPredicate, @@ -53,7 +54,8 @@ inNotInPredicate, typePredicate, idPredicate, - specialCharsPredicate]; + specialCharsPredicate, + booleanPredicate]; } - (void)testAllPredicates