github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/updater/osx/Updater/NSDictionary+Extension.m (about) 1 // 2 // NSDictionary+Extension.m 3 // Updater 4 // 5 // Created by Gabriel on 4/19/16. 6 // Copyright © 2016 Keybase. All rights reserved. 7 // 8 9 #import "NSDictionary+Extension.h" 10 11 @implementation NSDictionary (Extension) 12 13 - (BOOL)kb_boolForKey:(id)key withDefault:(BOOL)defaultValue { 14 id value = [self objectForKey:key]; 15 if (!value || [value isEqual:[NSNull null]]) return defaultValue; 16 // It can be error prone to check is something is a BOOL object type (NSNumber with internal bool), 17 // so we'll use boolValue. 18 if (![value respondsToSelector:@selector(boolValue)]) return defaultValue; 19 return [value boolValue]; 20 } 21 22 - (BOOL)kb_boolForKey:(id)key { 23 return [self kb_boolForKey:key withDefault:NO]; 24 } 25 26 - (NSString *)kb_stringForKey:(id)key { 27 id value = [self objectForKey:key]; 28 if (!value || [value isEqual:[NSNull null]]) return nil; 29 if (![value isKindOfClass:[NSString class]]) return nil; 30 return value; 31 } 32 33 - (NSArray<NSString *> *)kb_stringArrayForKey:(id)key { 34 id value = [self objectForKey:key]; 35 if (!value || [value isEqual:[NSNull null]]) return nil; 36 if (![value isKindOfClass:[NSArray class]]) return nil; 37 for (id obj in value) { 38 if (![obj isKindOfClass:NSString.class]) return nil; 39 } 40 return value; 41 } 42 43 @end