码迷,mamicode.com
首页 > 移动开发 > 详细

IOS开发之—— model最原始的封装,MJExtension加入工程(后续model都继承于它)

时间:2016-04-11 20:50:57      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!