This repository has been archived by the owner on Feb 5, 2021. It is now read-only.
forked from jofell/Photon---iPhoto-Blog-Export
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DKNSDictionaryExtensions.m
109 lines (97 loc) · 3 KB
/
DKNSDictionaryExtensions.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// DKNSDictionaryExtensions.m
// PhotoToTypePad
//
// Created by Jonathan Younger on Thu Jun 17 2004.
// Copyright (c) 2004 Daikini Software. All rights reserved.
//
#import "DKNSDictionaryExtensions.h"
@implementation NSDictionary (DKNSDictionaryExtensions)
// Invokes objectForKey: with key defaultName.
// Returns YES if the value associated with defaultName is an NSString containing the word “yesâ€
// in uppercase or lowercase or responds to the intValue message by returning a nonzero value.
// Otherwise, returns NO.
- (BOOL)boolForKey:(NSString *)defaultName
{
id returnValue = [self objectForKey:defaultName];
if (returnValue != nil) {
if ([returnValue isKindOfClass:[NSString class]]) {
if (([[returnValue lowercaseString] isEqualToString:@"yes"]) || ([returnValue intValue] != 0)) {
return YES;
}
} else if ([returnValue isKindOfClass:[NSNumber class]]) {
return [returnValue intValue] != 0;
}
}
return NO;
}
// Invokes objectForKey: with key defaultName.
// Returns 0 if no string is returned.
// Otherwise, the resulting string is sent an intValue message, which provides this method’s return value.
- (int)integerForKey:(NSString *)defaultName
{
id returnValue = [self objectForKey:defaultName];
if (returnValue != nil) {
if (([returnValue isKindOfClass:[NSString class]]) || ([returnValue isKindOfClass:[NSNumber class]])) {
return [returnValue intValue];
}
}
return 0;
}
// Invokes objectForKey: with key defaultName.
// Returns the corresponding value if it is an NSArray object containing NSStrings,
// and nil otherwise.
- (NSArray *)stringArrayForKey:(NSString *)defaultName
{
NSEnumerator *e;
id arrayObject;
id returnValue = [self objectForKey:defaultName];
if ([returnValue isKindOfClass:[NSArray class]]) {
e = [returnValue objectEnumerator];
while (arrayObject = [e nextObject]) {
if (![arrayObject isKindOfClass:[NSString class]]) {
return nil;
}
}
} else {
return nil;
}
return returnValue;
}
// Invokes objectForKey: with key defaultName.
// Returns the corresponding value if it is an NSString object
// and nil otherwise.
- (NSString *)stringForKey:(NSString *)defaultName
{
id returnValue = [self objectForKey:defaultName];
if ([returnValue isKindOfClass:[NSString class]]) {
return returnValue;
} else {
return nil;
}
}
// Invokes objectForKey: with key defaultName.
// Returns the value associated with defaultName if itÕs an NSArray object
//and nil otherwise.
- (NSArray *)arrayForKey:(NSString *)defaultName
{
id returnValue = [self objectForKey:defaultName];
if ([returnValue isKindOfClass:[NSArray class]]) {
return returnValue;
} else {
return nil;
}
}
// Invokes objectForKey: with key defaultName.
// Returns the corresponding value if itÕs an NSDictionary object
// and nil otherwise.
- (NSDictionary *)dictionaryForKey:(NSString *)defaultName
{
id returnValue = [self objectForKey:defaultName];
if ([returnValue isKindOfClass:[NSDictionary class]]) {
return returnValue;
} else {
return nil;
}
}
@end