diff --git a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h index ed5931f..6ae8fc6 100644 --- a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h +++ b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h @@ -24,6 +24,9 @@ - (CGFloat)floatForKey:(nonnull id)key; - (double)doubleForKey:(nonnull id)key; +// Not strict, can accept either string or boolean. +- (BOOL)lenientBoolForKey:(nonnull id)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. diff --git a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m index 8de5180..f4e087d 100644 --- a/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m +++ b/MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m @@ -32,6 +32,15 @@ return [[self objectForKey:key ofType:[NSNumber class]] boolValue]; } +- (BOOL)lenientBoolForKey:(nonnull id)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)key { return [[self objectForKey:key ofType:[NSNumber class]] floatValue]; }