Recommended way to declare delegate properties with ARC(使用 ARC 声明委托属性的推荐方法)
问题描述
我曾经将所有委托属性声明为
I used to declare all delegate properties as
@property (assign) id<FooDelegate> delegate;
我的印象是所有的赋值属性现在都应该是弱指针,这是正确的吗?如果我尝试声明为:
I was under the impression that all assign properties should now be weak pointers, is this correct? If I try to declare as:
@property (weak) id<FooDelegate> delegate;
尝试@synthesize 时出现错误(不支持自动生成的弱属性).
I get an error while trying to @synthesize (autogenerated weak properties are not supported).
在这种情况下,最佳做法是什么?
What's the best practice in this case?
推荐答案
对于面向 iOS 4 和 5 的 ARC 项目,使用 __unsafe_unretained 而不是 weak.唯一的区别是 weak 释放时指针为零,仅在 iOS 5 中支持.
Use __unsafe_unretained instead weak for ARC projects targeting iOS 4 and 5. The only difference is that weak nils the pointer when deallocated, and it's only supported in iOS 5.
为什么 Objective-C 委托通常被赋予属性 assign 而不是保留?.
这篇关于使用 ARC 声明委托属性的推荐方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 ARC 声明委托属性的推荐方法
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
