Created
December 6, 2015 15:06
-
-
Save thiagolioy/129fb6412de8e1c8129b to your computer and use it in GitHub Desktop.
Bricks! Mantle parse
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 BKBaseMantleObj : MTLModel<MTLJSONSerializing> | |
+ (NSDictionary *)JSONKeyPathsByPropertyKey; | |
+(instancetype)parse:(NSDictionary*)dc error:(NSError**)error; | |
-(NSDictionary*)asDictError:(NSError**)error; | |
@end | |
@interface BKBaseMantleObj (Collections) | |
+(NSArray*)asArrayOfDictFromModelArray:(NSArray*)objects error:(NSError**)error; | |
+(NSArray*)parseArray:(NSArray*)objs error:(NSError**)error; | |
@end | |
@implementation BKBaseMantleObj | |
+ (NSDictionary *)JSONKeyPathsByPropertyKey { | |
return [NSDictionary mtl_identityPropertyMapWithModel:self.class]; | |
} | |
-(NSDictionary*)asDictError:(NSError**)error{ | |
return [MTLJSONAdapter JSONDictionaryFromModel:self error:error]; | |
} | |
+(instancetype)parse:(NSDictionary*)dc error:(NSError**)error{ | |
return [MTLJSONAdapter modelOfClass:self.class | |
fromJSONDictionary:dc | |
error:error]; | |
} | |
@end | |
@implementation BKBaseMantleObj (Collections) | |
+(NSArray*)asArrayOfDictFromModelArray:(NSArray*)objects error:(NSError**)error{ | |
return [MTLJSONAdapter JSONArrayFromModels:objects error:error]; | |
} | |
+(NSArray*)parseArray:(NSArray*)objs error:(NSError**)error{ | |
return [MTLJSONAdapter modelsOfClass:self.class | |
fromJSONArray:objs | |
error:error]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment