[英]Why are UIKit delegates “assign”ed instead of “weak”?
As the title states, why are UIKit
delegates (assign)
instead of (weak)
? 正如标题所述,为什么
UIKit
代表(assign)
代替(weak)
?
See UIPopovercontroller.h
for example: 例如,请参阅
UIPopovercontroller.h
:
@property (nonatomic, assign) id <UIPopoverControllerDelegate> delegate;
As far as I can tell this provides no benefits over a weakly retained property but a lot of problems where the delegate needs to manage it's own lifetime as a delegate. 据我所知,这对于弱保留的属性没有任何好处,但是代理需要管理它作为代表的生命周期的许多问题。 It this a backwards compatibility issue?
这是一个向后兼容问题吗?
Thanks 谢谢
Because most of those properties existed before the iOS SDK supported weak properties. 因为大多数这些属性在iOS SDK支持的弱属性之前就已存在。 The
weak
attribute is only supported on iOS 5.0 and later. 仅在iOS 5.0及更高版本上支持
weak
属性。
I would have to guess that once iOS 4.x and earlier is history, they will all be updated to weak
. 我不得不猜测,一旦iOS 4.x及更早版本成为历史,它们将全部更新为
weak
。
UIKit is still built without ARC, therefore none of the UIKit classes can use weak references. UIKit仍然没有ARC构建,因此UIKit类都不能使用弱引用。 Even newer classes like UICollectionView use assign for their delegate properties for this reason.
因此,即使像UICollectionView这样的新类也会为其委托属性使用assign。
Delegates should never be retained. 不应保留代表。 That's an easy path to a retain cycle.
这是保留周期的简单途径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.