-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBCDictionaryExtensions.m
More file actions
46 lines (28 loc) · 956 Bytes
/
BCDictionaryExtensions.m
File metadata and controls
46 lines (28 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// BCDictionaryExtensions.m
// Caravan
//
// Created by Tom Houpt on 15/3/18.
// Copyright (c) 2015 Tom Houpt. All rights reserved.
//
#import "BCDictionaryExtensions.h"
@implementation NSDictionary (BCExtensions)
-(NSObject *) objectAtKeyPath:(NSString *)path;{
NSDictionary *currentDictionary = self;
NSArray *keys = [path componentsSeparatedByString:@"/"];
for (NSString *eachKey in keys) {
NSObject *nextObject = [currentDictionary objectForKey:eachKey];
if (eachKey == [keys lastObject]) {
return nextObject;
}
if (nextObject == nil) {
return nextObject;
}
else if (![nextObject isKindOfClass:[NSDictionary class]]) {
return nil;
}
currentDictionary = (NSDictionary *)nextObject;
}
return nil;
}
@end