Objective-C ARC: strong vs retain and weak vs assign

后端 未结 8 2420
眼角桃花
眼角桃花 2020-11-22 15:59

There are two new memory management attributes for properties introduced by ARC, strong and weak.

Apart from copy, which is ob

8条回答
  •  轮回少年
    2020-11-22 16:09

    From the Transitioning to ARC Release Notes (the example in the section on property attributes).

    // The following declaration is a synonym for: @property(retain) MyClass *myObject;
    
    @property(strong) MyClass *myObject;
    

    So strong is the same as retain in a property declaration.

    For ARC projects I would use strong instead of retain, I would use assign for C primitive properties and weak for weak references to Objective-C objects.

提交回复
热议问题