Skip to content

Instantly share code, notes, and snippets.

@thiagolioy
Created December 6, 2015 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagolioy/129fb6412de8e1c8129b to your computer and use it in GitHub Desktop.
Save thiagolioy/129fb6412de8e1c8129b to your computer and use it in GitHub Desktop.
Bricks! Mantle parse
@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