第三方框架-01.MJExtension基本使用

1.介绍

  • MJExtension为目前非常流行的数据转模型和模型转数据的第三方框架

2.基本使用

  • 常规字典转模型方法
// 懒加载
- (NSArray *)tgs
{
    if (!_tgs) {
    // 1.拿到plist文件路径
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil];
    // 2.根据路径创建字典数组
    NSArray *dictTgs = [NSArray arrayWithContentsOfFile:filePath];
    // 3.将字典数组转模型数组
    NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:dictTgs.count];
    for (NSDictionary *dict in dictTgs) {
    XMGTg *tg = [XMGTg tgWithDict:dict];
    [arrayM addObject:tg];
    }
    _tgs = [arrayM copy];

    }
    return _tgs;
}
  • 使用一: 直接通过文件名创建模型数组
// 懒加载
- (NSArray *)tgs
{
    if (!_tgs) {
        _tgs = [XMGTg objectArrayWithFilename:@"tgs.plist"];
    }
    return _tgs;
}
  • 使用二:通过文件路径将json数据转换为模型数组
- (NSArray *)tgs{
// 1.拿到plist文件路径
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil];
// 这是通过文件路径将plist文件中的json数据转成模型数组
    _tgs = [XMGTg objectArrayWithFile:filePath];
    return _tgs; 
}
  • 使用三:将字典数组转换为模型数组
- (NSArray *)tgs{
// 1.拿到plist文件路径
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil];
// 2.根据路径创建字典数组
    NSArray *dictTgs = [NSArray arrayWithContentsOfFile:filePath];
// 3.将字典数组转成模型数组的方法(MJExtension中)
    _tgs = [XMGTg objectArrayWithKeyValuesArray:dictTgs];
    return _tgs; 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值