lenient bool.... web view clean up

This commit is contained in:
Pfeil, Scott Robert 2018-10-30 14:29:11 -04:00
parent adda2f461b
commit c860e20258
2 changed files with 12 additions and 0 deletions

View File

@ -24,6 +24,9 @@
- (CGFloat)floatForKey:(nonnull id<NSCopying>)key;
- (double)doubleForKey:(nonnull id<NSCopying>)key;
// Not strict, can accept either string or boolean.
- (BOOL)lenientBoolForKey:(nonnull id<NSCopying>)key;
// Gets an object that is nested using a series of keys or indexes to reach it.
// All keys should be of type NSString and is used for nested dictionaries.
// All indexes should be of type NSNumber and is used for nested arrays.

View File

@ -32,6 +32,15 @@
return [[self objectForKey:key ofType:[NSNumber class]] boolValue];
}
- (BOOL)lenientBoolForKey:(nonnull id<NSCopying>)key {
NSObject *object = [self objectForKey:key];
if ([object isKindOfClass:[NSString class]]) {
return [((NSString *)object) isEqualToString:@"true"];
} else {
return [((NSNumber *)([object isKindOfClass:[NSNumber class]] ? object : nil)) boolValue];
}
}
- (CGFloat)floatForKey:(nonnull id<NSCopying>)key {
return [[self objectForKey:key ofType:[NSNumber class]] floatValue];
}