使用ARC声明委托属性的推荐方法 [英] Recommended way to declare delegate properties with ARC

查看:133
本文介绍了使用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?

推荐答案

使用 __ unsafe_unretained 而不是 weak 用于针对iOS 4和5的ARC项目。唯一的区别是 weak nils指针在释放时,它只支持在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而不是retain ?

这篇关于使用ARC声明委托属性的推荐方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆