首页 > 代码库 > TableView中Model层数据

TableView中Model层数据

TableView中Model层数据
一、如果plist文件中的形式:NSArray —> NSDictionary —>NSArray
最外层的字典
+ (instancetype)carGroupsWithDict:(NSDictionary*)dict
{
   
return [[selfalloc]initWithDict:dict];
}

- (
instancetype)initWithDict:(NSDictionary*)dict
{
   
self = [superinit];
    [
selfsetValue:dict[@"title"]forKey:@"title"];
   
self.carGroups= [SUNCarcarsWithArray:dict[@"cars"]];
   
return self;
}

+ (
NSArray*)carGroups
{
   
NSArray *array = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"cars_total.plist"ofType:nil]];
   
NSMutableArray *arrayM = [NSMutableArrayarray];
   
for (NSDictionary*dict in array) {
        [arrayM
addObject:[selfcarGroupsWithDict:dict]];
    }
   
return arrayM;
}

最里层的数组
+ (instancetype)carWithDict:(NSDictionary*)dict
{
   
return [[selfalloc]initWithDict:dict];
}

- (
instancetype)initWithDict:(NSDictionary*)dict
{
   
self = [superinit];
    [
selfsetValuesForKeysWithDictionary:dict];
   
return self;
}

+ (
NSArray*)carsWithArray:(NSArray*)array
{
   
NSMutableArray *arrayM = [NSMutableArrayarray];
   
for (NSDictionary*dict in array) {
        [arrayM
addObject:[selfcarWithDict:dict]];
    }
        
return arrayM;
}

二、如果plist文件中的形式:NSArray —> NSDictionary 
+ (instancetype)tgWithDict:(NSDictionary*)dict
{
   
return [[selfalloc]initWithDict:dict];
}
- (
instancetype)initWithDict:(NSDictionary*)dict
{
   
self = [superinit];
   
if (self) {
        [
selfsetValuesForKeysWithDictionary:dict];
    }
   
return self;
}

+ (
NSMutableArray*)tgs
{
   
NSArray *array = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"tgs.plist"ofType:nil]];
   
   
NSMutableArray *arrayM = [NSMutableArrayarray];
   
for (NSDictionary*dict in array) {
        [arrayM
addObject:[selftgWithDict:dict]];
    }
   
return arrayM;
}

TableView中Model层数据