Created
April 25, 2013 14:08
-
-
Save nickjshearer/5459985 to your computer and use it in GitHub Desktop.
Mantle Example
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
@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