Created
August 26, 2013 14:08
-
-
Save shsteven/6341798 to your computer and use it in GitHub Desktop.
NSObject+DictionaryRepresentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSObject (TSDictionaryRepresentation) | |
/** | |
Turns an object into NSDictionary, for API requests | |
*/ | |
- (NSDictionary *)dictionaryRepresentationWithMapping: (NSDictionary *)mapping { | |
NSMutableDictionary *mutableDict = [NSMutableDictionary new]; | |
[mapping enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
id value = [self valueForKey:key]; | |
if ([value isKindOfClass:[NSDate class]]) { | |
// Phoenix uses /Date(xxxxxxxx)/ format | |
value = [[TSPhoenixClient sharedInstance].defaultDateFormatter stringFromDate:value]; | |
} | |
if (value) | |
mutableDict[obj] = value; | |
}]; | |
return [mutableDict copy]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment