首页 > 其他 > 详细

解決在 Xcode 5.1环境下property所造成的 synthesis warning问题?

时间:2014-04-08 16:14:34      阅读:1202      评论:0      收藏:0      [点我收藏+]

Xcode 升级到最新的 5.1,在使用AFNetworking时遇到了 property synthesis 相关的 error,错误信息如下:

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

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

AFHTTPRequestOperation中定义了:


@property (readwrite, nonatomic, strong) NSURLRequest *request;

@property (readwrite, nonatomic, strong) NSHTTPURLResponse *response;



就是这样的代码,会让 request property 出现 warning。原因是因为 compiler 读取 sub-class 時,会发现 request 明明应该是個 readonly propertysuper-class 讲的),但你却要将它设为 readwriteproperty,所以 compiler 不知道该怎么 auto synthesis

但你知道 super-class 的实现,也会将这个 property 改成 readwrite,因此你在 sub-class 的实现里这样子写是不会有问题的。可是 compiler 不知道啊,這要怎么办呢?

你要告诉 compiler,要它不用担心。那要怎么告诉 compiler 呢?你需要的是 @dynamic,它是一种给 compiler 的「承诺」,承诺它「虽然你现在不知道该怎么办,但是在 runtime 的时候你就会知道了」。所以只要把代码改成以下这样就可以了:

@implementation AFHTTPRequestOperation

@dynamic response;

@dynamic request;


@end

解決在 Xcode 5.1环境下property所造成的 synthesis warning问题?,布布扣,bubuko.com

解決在 Xcode 5.1环境下property所造成的 synthesis warning问题?

原文:http://blog.csdn.net/pjk1129/article/details/23163875

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!