标签:
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
IOS开发之—— model最原始的封装,MJExtension加入工程(后续model都继承于它)
标签:
原文地址:http://www.cnblogs.com/linxiu-0925/p/5379901.html