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

解析後臺返回的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 = [AModelobjectWithKeyValues:dic];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章