1// Copyright © 2021 650 Industries. All rights reserved. 2 3#import <EXJSONUtils/NSDictionary+EXJSONUtils.h> 4 5#define EXGetNonNullManifestValue(Type, key) \ 6({ \ 7 id value = [self objectForKey:key]; \ 8 NSAssert(value != nil, @"Value for (key = %@) should not be null", key); \ 9 NSAssert([value isKindOfClass:[Type class]], @"Value for (key = %@) should be a %@", key, NSStringFromClass([Type class])); \ 10 value; \ 11}) 12 13#define EXGetNullableManifestValue(Type, key) \ 14({ \ 15 id value = [self objectForKey:key]; \ 16 NSAssert(!value || [value isKindOfClass:[Type class]], @"Value for (key = %@) should be a %@ or null", key, NSStringFromClass([Type class])); \ 17 value; \ 18}) 19 20@implementation NSDictionary (EXJSONUtils) 21 22- (NSString *)expo_stringForKey:(id)key { 23 return EXGetNonNullManifestValue(NSString, key); 24} 25 26- (nullable NSString *)expo_nullableStringForKey:(id)key { 27 return EXGetNullableManifestValue(NSString, key); 28} 29 30- (NSNumber *)expo_numberForKey:(id)key { 31 return EXGetNonNullManifestValue(NSNumber, key); 32} 33 34- (nullable NSNumber *)expo_nullableNumberForKey:(id)key { 35 return EXGetNullableManifestValue(NSNumber, key); 36} 37 38- (NSArray *)expo_arrayForKey:(id)key { 39 return EXGetNonNullManifestValue(NSArray, key); 40} 41 42- (nullable NSArray *)expo_nullableArrayForKey:(id)key { 43 return EXGetNullableManifestValue(NSArray, key); 44} 45 46- (NSDictionary *)expo_dictionaryForKey:(id)key { 47 return EXGetNonNullManifestValue(NSDictionary, key); 48} 49 50- (nullable NSDictionary *)expo_nullableDictionaryForKey:(id)key { 51 return EXGetNullableManifestValue(NSDictionary, key); 52} 53 54@end 55