Skip to content

Instantly share code, notes, and snippets.

@nickjshearer
Created April 25, 2013 14:08
Show Gist options
  • Save nickjshearer/5459985 to your computer and use it in GitHub Desktop.
Save nickjshearer/5459985 to your computer and use it in GitHub Desktop.
Mantle Example
@interface Article : MTLModel <MTLJSONSerializing>
@property (nonatomic) NSString *title;
@property (nonatomic) NSString *body;
@property (nonatomic) NSURL *url;
@property (nonatmoic) NSDate *dateModified;
@implementation Article
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"title": @"title",
@"body": @"body",
@"url": @"url",
@"dateModified": @"modified"
};
}
+ (NSValueTransformer *)URLJSONTransformer {
return [NSValueTransformer valueTransformerForName:MTLURLValueTransformerName];
}
+ (NSValueTransformer *)dateModifiedJSONTransformer {
return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSString *str) {
return [self.dateFormatter dateFromString:str];
} reverseBlock:^(NSDate *date) {
return [self.dateFormatter stringFromDate:date];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment