这是一个小坑, 看看你的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;
}

 

相关文章:

  • 2021-08-10
  • 2021-05-05
  • 2022-12-23
  • 2021-10-21
  • 2021-06-17
  • 2022-12-23
  • 2021-05-03
  • 2021-12-09
猜你喜欢
  • 2021-05-11
  • 2022-12-23
  • 2021-07-23
  • 2021-12-01
  • 2021-09-08
相关资源
相似解决方案