DMBasicDataModel.h
#import <Foundation/Foundation.h>
@interface DMBasicDataModel : NSObject
- (id)initWithDictionary:(NSDictionary *)dictionary;
@end
DMBasicDataModel.m
#import "DMBasicDataModel.h"
@implementation DMBasicDataModel
- (id)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
// if (dictionary != nil) {
// for (NSString *key in [dictionary allKeys]) {
// [self setValue:[NSString stringWithFormat:@"%@",dictionary[key]] forKeyPath:key];
// }
//// [self setValuesForKeysWithDictionary:dictionary];
// }
/**
* 通过字典来创建一个模型
* @param keyValues 字典(可以是NSDictionary、NSData、NSString)
* @return 新建的对象
*/
self = [[self class]objectWithKeyValues:dictionary];
}
return self;
}
//重写,防止kvc无法找到key时崩溃
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
}
@end