MJExtension浅析


#import "ViewController.h"
#import "XMGTgCell.h"
#import "XMGTg.h"
#import "MJExtension.h"

@interface ViewController ()
/** 所有的团购数据*/
@property (nonatomic ,strong) NSArray *tgs;
@end

@implementation ViewController

#pragma mark - 懒加载
- (NSArray *)tgs
{
    if (!_tgs) {
        // 加载字典数组
//        NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil]];

//        // 字典数组->模型数组
//        NSMutableArray *temp = [NSMutableArray array];
//        for (NSDictionary *dict in dictArray) {
//            [temp addObject:[XMGTg tgWithDict:dict]];
//        }
//        _tgs = temp;
//        _tgs = [XMGTg mj_objectArrayWithKeyValuesArray:dictArray];
//        _tgs = [XMGTg mj_objectArrayWithFile:[[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil]];

//        _tgs = [XMGTg mj_objectArrayWithFilename:@"tgs.plist"];

        // 通过plist来创建一个模型数组
        _tgs = [XMGTg mj_objectArrayWithFilename:@"tgs.plist"];
    }
    return _tgs;
}



#import "ViewController.h"
#import "XMGCarGroup.h"
#import "XMGCar.h"
#import "MJExtension.h"
@interface ViewController ()

/** 所有的车数据*/
@property (nonatomic ,strong) NSArray *carGoups;
@end

@implementation ViewController


- (NSArray *)carGoups
{
    if (!_carGoups) {
        // 告诉MJExtension这个框架XMGCarGroup的cars数组属性中装的是XMGCar 模型
        [XMGCarGroup mj_setupObjectClassInArray:^NSDictionary *{
            return @{@"cars" : [XMGCar class]};
        }];

        _carGoups = [XMGCarGroup mj_objectArrayWithFilename:@"cars.plist"];
    }
    return _carGoups;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容