美文网首页
2020-08-05 转模型报错Auto property sy

2020-08-05 转模型报错Auto property sy

作者: 缘來諟夢 | 来源:发表于2020-08-05 16:35 被阅读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];
    

    作者:程序圆圆
    链接:https://www.jianshu.com/p/48d141ae351f
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

    相关文章

      网友评论

          本文标题:2020-08-05 转模型报错Auto property sy

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