Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios] Check for bool value with char
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
boundsj committed Sep 1, 2016
1 parent e07c2c4 commit eefe5cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion platform/darwin/src/NSExpression+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @implementation NSExpression (MGLAdditions)
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 };
}
}
Expand Down
4 changes: 3 additions & 1 deletion platform/darwin/test/MGLFilterTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ - (void)tearDown
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,
Expand All @@ -53,7 +54,8 @@ - (void)tearDown
inNotInPredicate,
typePredicate,
idPredicate,
specialCharsPredicate];
specialCharsPredicate,
booleanPredicate];
}

- (void)testAllPredicates
Expand Down

0 comments on commit eefe5cb

Please sign in to comment.