美文网首页
转模型报错Auto property synthesis wil

转模型报错Auto property synthesis wil

作者: 炸街程序猿 | 来源:发表于2018-08-06 15:53 被阅读0次

解析后台返回的json数据时,推荐使用MJExtension ,使用起来很方便

github:https://github.com/CoderMJLee/MJExtension

在AModel.h中

@property(nonatomic,strong) NSString *description;

出现提示warning:

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

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

解决办法:

AModel.m

@implementation AModel

@dynamic description;

@end

但是刚从后台拿数据时,用MJExtension.h解析数据时,还是拿不到数据。

后台返回的字典里的字段是description,但是可以在model里用Description来表示,大写的D。

在AModel.m里实现

+(NSDictionary *)replacedKeyFromPropertyName{

 return @{@"Description":@"description"};

}

核心代码:

AModel *subM = [AModel objectWithKeyValues:dic];

相关文章

网友评论

      本文标题:转模型报错Auto property synthesis wil

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