|
[Objective-C] Fixes crash in case of missing of the partial KeyPath |
|
 |
@implementation NSDictionary (Values)
- (id)valueForKeyPath:(NSString *)keyPath
{
__block id value = nil;
if (keyPath != nil) {
NSArray *keys = [keyPath componentsSeparatedByString:@"."];
if (keys && [keys count] > 0) {
[keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
value = idx == 0 ? [self objectForKey:obj] : [value objectForKey:obj];
if (value == nil || ![value isKindOfClass:[NSDictionary class]])
*stop = YES;
}];
}
}
return value;
}
|
|
|
|
|
|
|
|
Copyright © 1996-2021 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581. |
|
|
|