From c860e20258bd8aec6dc92e8f8144d568006d3e88 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 30 Oct 2018 14:29:11 -0400 Subject: [PATCH] lenient bool.... web view clean up --- MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.h | 3 +++ MVMCore/MVMCore/Categories/NSDictionary+MFConvenience.m | 9 +++++++++ 2 files changed, 12 insertions(+) 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]; }