1// Copyright © 2021 650 Industries. All rights reserved. 2 3#import <ABI47_0_0EXJSONUtils/NSDictionary+ABI47_0_0EXJSONUtils.h> 4 5#define ABI47_0_0EXGetNonNullManifestValue(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 ABI47_0_0EXGetNullableManifestValue(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 (ABI47_0_0EXJSONUtils) 21 22- (NSString *)stringForKey:(id)key { 23 return ABI47_0_0EXGetNonNullManifestValue(NSString, key); 24} 25 26- (nullable NSString *)nullableStringForKey:(id)key { 27 return ABI47_0_0EXGetNullableManifestValue(NSString, key); 28} 29 30- (NSNumber *)numberForKey:(id)key { 31 return ABI47_0_0EXGetNonNullManifestValue(NSNumber, key); 32} 33 34- (nullable NSNumber *)nullableNumberForKey:(id)key { 35 return ABI47_0_0EXGetNullableManifestValue(NSNumber, key); 36} 37 38- (NSArray *)arrayForKey:(id)key { 39 return ABI47_0_0EXGetNonNullManifestValue(NSArray, key); 40} 41 42- (nullable NSArray *)nullableArrayForKey:(id)key { 43 return ABI47_0_0EXGetNullableManifestValue(NSArray, key); 44} 45 46- (NSDictionary *)dictionaryForKey:(id)key { 47 return ABI47_0_0EXGetNonNullManifestValue(NSDictionary, key); 48} 49 50- (nullable NSDictionary *)nullableDictionaryForKey:(id)key { 51 return ABI47_0_0EXGetNullableManifestValue(NSDictionary, key); 52} 53 54@end 55