What are the new type qualifiers introduced with ARC?

后端 未结 3 1416
天涯浪人
天涯浪人 2021-02-01 21:44

Automatic Reference Counting (ARC) introduces some new type qualifiers. I\'ve seen __strong and __weak, but what do they do?

3条回答
  •  你的背包
    2021-02-01 21:52

    Strong tells ARC to retain the property.

    @property (strong,nonatomic) NSObject *object;
    @property (retain,nonatomic) NSObject *object;
    

    Weak is essentially assign, a unretained property. Except the when the object is deallocated the weak pointer is automatically set to nil.

    @property (weak,nonatomic) NSObject *object;
    @property (assign,nonatomic) NSObject *object;
    

    Weak is only available on iOS 4.3 and up. If you want to target iOS 4.2 you need to use unsafe_unretained, that will work exactly like assign used to.

提交回复
热议问题