// // KWMCemaroseResult.m // iCemarose // // Created by HouWeiBin on 2016/10/20. // Copyright © 2016年 kollway. All rights reserved. // #import "KWMCemaroseResult.h" @implementation KWMCemaroseResult - (instancetype)initWithDictionary:(NSDictionary *)dict modelClass:(Class)modelClass error:(NSError **)err { self = [super initWithDictionary:dict error:err]; return self; } - (id)buildData:(Class)modelClass jsonDictionary:(NSDictionary *)jsonDictionary { id result = nil; if(modelClass != nil){ NSError *error; id tmpResult = [[modelClass alloc] initWithDictionary:jsonDictionary error:&error]; if(error){ NSLog(@"buildData error: %@", [error localizedDescription]); }else{ result = tmpResult; } } return result; } - (NSArray *)buildListData:(Class)modelClass jsonDictionary:(NSArray *)dataArray { if(modelClass == nil){ NSString *reason = [[NSString alloc] initWithFormat:@"class with name:%@ doesn't exists!!", NSStringFromClass(modelClass)]; @throw [[NSException alloc] initWithName:NSInvalidArgumentException reason:reason userInfo:nil]; } if(! [dataArray isKindOfClass:[NSArray class]]){ NSString *reason = [[NSString alloc] initWithFormat:@"dataArray object is not a NSArray instance"]; @throw [[NSException alloc] initWithName:NSInvalidArgumentException reason:reason userInfo:nil]; } NSMutableArray *mutableArray = [[NSMutableArray alloc] init]; for(NSDictionary *itemJson in dataArray){ NSError *error; id result = [[modelClass alloc] initWithDictionary:itemJson error:&error]; if(error){ NSLog(@"buildListData error: %@", [error localizedDescription]); }else{ [mutableArray addObject:result]; } } return [[NSArray alloc] initWithArray:mutableArray]; } +(JSONKeyMapper*)keyMapper { return [JSONKeyMapper mapperFromUnderscoreCaseToCamelCase]; } @end