繼承NSObject
//這里基本上處理服務器返回的數(shù)據(jù)
//接著上面點評的api寫的數(shù)據(jù)
//這里就簡單處理一組數(shù)據(jù),其中用到了2個封裝(字典轉模型)
.h
+(NSArray *)getAllSorts;
.m
//2個封裝,前提是從Plist文件中讀數(shù)據(jù)溶锭;->數(shù)組潛逃字典的樣式
-(NSArray *)getAndParseWithPlistFile:(NSString *)plistFileName withClass:(Class)modelClass {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:plistFileName ofType:nil];
//從plist讀取數(shù)據(jù)
NSArray *plistArray =[NSArray arrayWithContentOfFile:plistPath];
NSArray *returnArray = [self getArrayWithArray :plistArray withClass :modelClass];
return returnArray;
//把數(shù)組中的字典循環(huán)轉成模型對象贸毕,并返回數(shù)組
-(NSArray *)getArrayWithArray:(NSArray *)array withClass:(Class)modelClass {
//將字典轉成模型對象(類型不一樣); 返回
NSMutableArray *mutableArray = [NSMutableArray array];
for (NSDictionary *dic in array) {
id model = [modelClass new];
//KVC轉換
[model setValuesForKeysWithDictionary:dic];
[mutableArray addObject:model];
}
return [mutableArray copy];
}