MJExtension浅析
2016-07-22 本文已影响261人
Z了个L
#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;
}