我曾经将所有委托(delegate)属性声明为
@property (assign) id<FooDelegate> delegate;
我的印象是所有赋值属性现在都应该是弱指针,这是正确的吗? 如果我尝试声明为:
@property (weak) id<FooDelegate> delegate;
我在尝试 @synthesize 时遇到错误(不支持自动生成的弱属性)。
在这种情况下,最佳做法是什么?
最佳答案
Xcode 4 重构> 转换为 Objective-C ARC 转换:
@interface XYZ : NSObject
{
id delegate;
}
@property (assign) id delegate;
...
@synthesize delegate;
进入:
@interface XYZ : NSObject
{
id __unsafe_unretained delegate;
}
@property (unsafe_unretained) id delegate;
...
@synthesize delegate;
如果我没记错的话,在 WWDC 2011 视频中也提到了 ARC。
关于objective-c - 使用 ARC 声明委托(delegate)属性的推荐方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7753841/