-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSDictionary+Path.m
36 lines (28 loc) · 1.01 KB
/
NSDictionary+Path.m
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
//
// NSDictionary+Path.m
// MazAudio
//
// Created by Gérald HUARD on 04/04/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "NSDictionary+Path.h"
@implementation NSDictionary (Path)
-(id)objectForPath:(NSString*)path{
NSDictionary *dictProgress=[self copy];
NSArray *strings = [path componentsSeparatedByString:@"/"];
NSString *lastkey=[strings lastObject];
for (int i=0;i<[strings count]-1;i++){
NSString *pth=[strings objectAtIndex:i];
if ([pth length]>0){
if ([dictProgress isKindOfClass:[NSDictionary class]])dictProgress=[dictProgress objectForKey:pth];
else {
@throw [NSException exceptionWithName:NSInvalidArchiveOperationException
reason:@"NSDictionnary::Path incorrect"
userInfo:nil];
return nil;
}
}
}
return [dictProgress objectForKey:lastkey];
}
@end