EightyEight
EightyEight

Reputation: 3460

Why are UIKit delegates "assign"ed instead of "weak"?

As the title states, why are UIKit delegates (assign) instead of (weak)?

See UIPopovercontroller.h for example:

@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

Upvotes: 6

Views: 1168

Answers (3)

Tuomas Artman
Tuomas Artman

Reputation: 76

UIKit is still built without ARC, therefore none of the UIKit classes can use weak references. Even newer classes like UICollectionView use assign for their delegate properties for this reason.

Upvotes: 2

rmaddy
rmaddy

Reputation: 318824

Because most of those properties existed before the iOS SDK supported weak properties. The weak attribute is only supported on iOS 5.0 and later.

I would have to guess that once iOS 4.x and earlier is history, they will all be updated to weak.

Upvotes: 10

jsd
jsd

Reputation: 7693

Delegates should never be retained. That's an easy path to a retain cycle.

Upvotes: -3

Related Questions