您的位置:首页 > 运维架构

Auto property synthesis will not synthesize property 'description' because it is 'readwrite' but it

2015-06-05 11:51 661 查看
解析后台返回的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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: