Mantle的使用

引用于如下两篇博客

https://github.com/Mantle/Mantle

http://blog.csdn.net/afdl9999/article/details/45631525

注意配置在header search path里配置三房库”$(SRCROOT)路径”

1.新建一个类如ml继承于MTLModel

2.遵守协议MTLJSONSerializing

3.如下

 @interface ml : MTLModel<MTLJSONSerializing>

 @property (nonatomic,strong) NSNumber *code;

 @property (nonatomic,strong) NSString *msg;

 @end

5.将下载的数据与我们想要显示的数据进行对应

+ (NSDictionary *)JSONKeyPathsByPropertyKey {

    return @{

@"code":@"code",

             @"msg" :@"msg",


                         };

}

6.进行相对应的转换方法

+(NSValueTransformer *)JSONTransformerForKey:(NSString *)key{

    

return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(NSNumber *dateNum) {

    return [NSDate dateWithTimeIntervalSince1970:dateNum.floatValue];

} reverseBlock:^(NSDate *date) {

    return [NSString stringWithFormat:@"%f",[date timeIntervalSince1970]];

}];

}

7.model数据转换为json数据

+(NSDictionary *)JSONDictionaryFromModel:(MTLModel<MTLJSONSerializing> *)model{

    return nil;

}


8.对象的存储


 [NSKeyArchiver archiveRootObject:model toFile:path];


9.对象的解档


ml *model = [NSKeyedUnarchiver unarchiveObjectWithFile:@""];

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值