升级到最新xcode,在使用AFNetworking时遇到了 property synthesis 相关的 error
来源:互联网 发布:微信公众号淘宝优惠券 编辑:程序博客网 时间:2024/05/18 18:00
將 Xcode 升级到最新,在使用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 property(super-class 讲的),但你却要将它设为 read write property,所以 compiler 不知道该怎么 auto synthesis。
但你知道 super-class 的实现,也会将这个 property 改成 readwrite,因此你在 sub-class 的实现里这样子写是不会有问题的。可是 compiler 不知道啊,這要怎么办呢?
你要告诉 compiler,要它不用担心。那要怎么告诉 compiler 呢?你需要的是 @dynamic,它是一种给 compiler 的「承诺」,承诺它「虽然你现在不知道该怎么办,但是在 runtime 的时候你就会知道了」。所以只要把代码改成以下这样就可以了:
@implementation AFHTTPRequestOperation
@dynamic response;
@dynamic request;
@end
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 property(super-class 讲的),但你却要将它设为 read write property,所以 compiler 不知道该怎么 auto synthesis。
但你知道 super-class 的实现,也会将这个 property 改成 readwrite,因此你在 sub-class 的实现里这样子写是不会有问题的。可是 compiler 不知道啊,這要怎么办呢?
你要告诉 compiler,要它不用担心。那要怎么告诉 compiler 呢?你需要的是 @dynamic,它是一种给 compiler 的「承诺」,承诺它「虽然你现在不知道该怎么办,但是在 runtime 的时候你就会知道了」。所以只要把代码改成以下这样就可以了:
@implementation AFHTTPRequestOperation
@dynamic response;
@dynamic request;
@end
0 0
- 升级到最新xcode,在使用AFNetworking时遇到了 property synthesis 相关的 error
- 使用AFNetworking时遇到了 property synthesis 相关的 error
- Xcode升级了6.3 出现的警告:Auto property synthesis will not synthesize property
- 解決在 Xcode 5.1环境下property所造成的 synthesis warning问题?
- 解決在 Xcode 5.1环境下property所造成的 synthesis warning问题?
- 使用AFNetworking上传多组图片时遇到的error
- xcode升级到4.5遇到的问题
- 把vs2003开发的项目升级到vs2008,在升级中遇到了很有多的问题
- Automatic Property Synthesis With Xcode 4.4
- 升级xcode到4.5后遇到的问题解决方法
- Xcode: Auto property synthesis will not synthesize property 解决
- ZXing在XCODE升级到4.6 IOS6.1的问题
- 手痒Xcode升级到5.1了
- 升级Mac OS X 和 Xcode的SVN到最新版本
- 升级Mac OS X 和 Xcode的SVN到最新版本
- 升级Mac OS X 和 Xcode的SVN到最新版本
- 使用GreenDao,遇到的升级问题。帮了大忙了!
- 在swift 中引入AFNetworking时遇到的问题
- IOS7.0 sizeWithFont:constrainedToSize:lineBreakMode:方法
- shell 修改xml文件 的参数值。
- Linux系统与程序监控工具atop教程
- C++ 拷贝构造函数 赋值构造函数
- Java编程思想(十六) —— 联系JVM再谈Class
- 升级到最新xcode,在使用AFNetworking时遇到了 property synthesis 相关的 error
- App适配iPhone 6/ Plus和iOS 8:10条小秘诀
- 【网络安全】Snort漏洞分析规则提取验证全流程讲述
- java统计代码行数
- web项目的性能分析
- debounce函数
- Android之仿今日头条顶部导航栏效果
- 简单的ant打包,修改渠道号
- 五级工程师分享之学习2015.01.09