-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUUDictionary.h
More file actions
72 lines (51 loc) · 2.27 KB
/
UUDictionary.h
File metadata and controls
72 lines (51 loc) · 2.27 KB
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
//
// UUDictionary.h
// Useful Utilities - Extensions for NSDictionary
//
// Created by Ryan DeVore on 4/18/14.
//
// License:
// You are free to use this code for whatever purposes you desire. The only requirement is that you smile everytime you use it.
//
// Contact: @cheesemaker or jon@threejacks.com
//
#import <Foundation/Foundation.h>
@interface NSDictionary (UUDictionary)
// Safely get the object at the specified key. If the object is NSNull, then
// nil will be returned.
- (id) uuSafeGet:(NSString*)key;
// Safely gets an object and verifies it is of the expected class type. If
// the value is NSNull or not of the expecting type, nil will be returned
- (id) uuSafeGet:(NSString*)key forClass:(Class)forClass;
// Safely gets an object and verifies it is of the expected class type. If the
// value is NSNull or not of the expected type, the passed in default will be
// returned.
- (id) uuSafeGet:(NSString*)key forClass:(Class)forClass defaultValue:(id)defaultValue;
// Safely gets an NSNumber. If the value is an NSString, this method will
// attempt to convert it to a number object using NSNumberFormatter
- (NSNumber*) uuSafeGetNumber:(NSString*)key;
- (NSNumber*) uuSafeGetNumber:(NSString*)key defaultValue:(NSNumber*)defaultValue;
// Safely gets an NSString
- (NSString*) uuSafeGetString:(NSString*)key;
- (NSString*) uuSafeGetString:(NSString*)key defaultValue:(NSString*)defaultValue;
// Safely gets a string object and formats is as an NSDate using the
// specified NSDateFormatter
- (NSDate*) uuSafeGetDate:(NSString*)key formatter:(NSDateFormatter*)formatter;
// Convenience wrappers
- (NSDictionary*) uuSafeGetDictionary:(NSString*)key;
- (NSArray*) uuSafeGetArray:(NSString*)key;
- (NSData*) uuSafeGetData:(NSString*)key;
- (NSData*) uuSafeGetData:(NSString*)key defaultValue:(NSData*)defaultValue;
- (NSData*) uuSafeGetDataFromBase64String:(NSString*)key;
@end
@interface NSDictionary (UUHttpDictionary)
// Builds a formatted query string from the dictionary arguments. Only handles
// value objects that are NSNumber or NSString.
- (NSString*) uuBuildQueryString;
- (NSString*) uuToJsonString;
- (NSData*) uuToJson;
@end
@interface NSMutableDictionary (UUMutableDictionary)
- (void) uuSafeSetValue:(id)value forKey:(NSString*)key;
- (void) uuSafeRemove:(id)key;
@end