-
Notifications
You must be signed in to change notification settings - Fork 0
/
TDUtils.h
53 lines (39 loc) · 1.68 KB
/
TDUtils.h
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
#import <Foundation/Foundation.h>
@interface TDUtils : NSObject
/**
Answer from http://stackoverflow.com/questions/754824/get-an-object-attributes-list-in-objective-c/13000074#13000074
Return dictionary of property name and type from a class.
Useful for Key-Value Coding. For example:
- (void)encodeWithCoder:(NSCoder *)encoder {
//Encode properties, other class variables, etc
NSDictionary* propertyDict = [Utils propertiesForClass:[self class]];
for (NSString* key in propertyDict) {
id value = [self valueForKey:key];
[encoder encodeObject:value forKey:key];
}
}
- (id)initWithCoder:(NSCoder *)decoder {
if((self = [super init])) {
//decode properties, other class vars
NSDictionary* propertyDict = [Utils propertiesForClass:[self class]];
for (NSString* key in propertyDict) {
id value = [decoder decodeObjectForKey:key];
[self setValue:value forKey:key];
}
}
return self;
}
*/
+ (NSDictionary *)propertiesForClass:(Class)cls;
/** Convert a dict to an object with predefined class. Useful for translate server json to object.
*/
+ (id) objectWithClass:(Class)cls fromDictionary:(NSDictionary*)dict;
/** Convert an array of dict to array of object with predefined class.
Useful for translate server json to object.
*/
+ (NSArray*) arrayOfClass:(Class)cls fromArrayOfDictionary:(NSArray*)array;
/** Validate email using Regex
Answer from http://stackoverflow.com/questions/800123/best-practices-for-validating-email-address-in-objective-c-on-ios-2-0
*/
+ (BOOL) validateEmail:(NSString*)email;
@end