Skip to content

Instantly share code, notes, and snippets.

@shsteven
Created August 26, 2013 14:08
Show Gist options
  • Save shsteven/6341798 to your computer and use it in GitHub Desktop.
Save shsteven/6341798 to your computer and use it in GitHub Desktop.
NSObject+DictionaryRepresentation
@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