Recommended way to declare delegate properties with ARC

前端 未结 2 984
Happy的楠姐
Happy的楠姐 2020-12-05 10:07

I used to declare all delegate properties as

@property (assign) id delegate;

I was under the impression that all assign

相关标签:
2条回答
  • 2020-12-05 10:39

    Xcode 4 Refactor > Convert to Objective-C ARC transforms:

    @interface XYZ : NSObject
    {
        id delegate;
    }
    @property (assign) id delegate;
    ...
    @synthesize delegate;
    

    into:

    @interface XYZ : NSObject
    {
        id __unsafe_unretained delegate;
    }
    @property (unsafe_unretained) id delegate;
    ...
    @synthesize delegate;
    

    If I remember correctly it is also mentioned in WWDC 2011 video about ARC.

    0 讨论(0)
  • 2020-12-05 10:43

    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.

    Your other question is answered in Why are Objective-C delegates usually given the property assign instead of retain?.

    0 讨论(0)
提交回复
热议问题