美文网首页
模型数据根据字典中的key值自动赋值

模型数据根据字典中的key值自动赋值

作者: 陈水寒 | 来源:发表于2016-10-27 16:00 被阅读14次
- (instancetype)initWithDict:(NSDictionary *)dict{
    if (self = [super init]) {
        // 一般方法如下,如果模型中有大量数据,一项一项写工作量很大
        //self.name= dict[@"name"];
        //self.icon= dict[@"icon"];
        
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

+ (instancetype)userModelWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}

相关文章

网友评论

      本文标题:模型数据根据字典中的key值自动赋值

      本文链接:https://www.haomeiwen.com/subject/mjcsuttx.html