zoukankan      html  css  js  c++  java
  • iOS -- 给model赋值时走了[self setValuesForKeysWithDictionary:dic]不走setvalue: forked:

    这是一个小坑, 看看你的BaseModel的便利构造器的方法:

    + (__kindof BaseModel *)modelWithDic:(NSDictionary *)dic {
        return [[self alloc] initWithDic:dic];
    }

    self 一定要写成self, 这样才会调用子类的setvalue的方法. 不要写成BaseModel. 

    BaseModel.m中的代码如下:

    - (instancetype)initWithDic:(NSDictionary *)dic {
        self = [super init];
        if (self) {
            [self setValuesForKeysWithDictionary:dic];
        }
        return self;
    }
    
    + (__kindof BaseModel *)modelWithDic:(NSDictionary *)dic {
        return [[self alloc] initWithDic:dic];
    }
    
    - (void)setValue:(id)value forUndefinedKey:(NSString *)key {
        
    }
    
    - (id)valueForUndefinedKey:(NSString *)key {
        return nil;
    }
  • 相关阅读:
    LVS DR模式的简单应用
    Linux新加硬盘如何识别 分区 持续挂载
    13周作业
    12周作业
    2次月考
    10周作业
    9周作业
    8周作业
    7周作业
    6周作业
  • 原文地址:https://www.cnblogs.com/mafeng/p/5848746.html
Copyright © 2011-2022 走看看