美文网首页
Auto property synthesis ...

Auto property synthesis ...

作者: 萝BAIBAI | 来源:发表于2015-11-15 19:07 被阅读190次

Auto property synthesis will not synthesize property 'description' because it is 'readwrote' but it will be synthesized 'readonly' via another property

想用MJExtension进行字典模型转换,模型头文件中定义了一个description属性
Model.h

@property (nonatomic, strong) NSString *description;

然后就出现了如上警告。

原因是因为 compiler 读取 sub-class 時,会发现 description 明明应该是個 readonly property(super-class 讲的),但你却要将它设为 readwrite property,所以 compiler 不知道该怎么 auto synthesis。

解决方法
Model.m

@implementation AModel

@dynamic description;

@end

这样虽然没了警告,但是还是取不到值。查看后的解决方法

+ (NSDictionary *)replacedKeyFromPropertyName{
    return @{@"Description":@"description"};
}

把属性名改成大写D开头,或者随便取一个属性名,然后用上面的方法,字典的key就是你定义的属性名,后面的就是你请求的后台数据对应的Key。问题解决。

相关文章

网友评论

      本文标题:Auto property synthesis ...

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