IOS, ARC, Property: (readwrite, nonatomic) vs (radwrite, retain, nonatomic)

后端 未结 2 1735
一生所求
一生所求 2020-12-20 10:07

I am have read up some tutorials on ARC and am still left a bit confused on properties declarations. I wrote most most my code using the following pattern:

@         


        
2条回答
  •  自闭症患者
    2020-12-20 10:33

    ARC is will retain object based on the property declaration, you should use strong for properties that need to be retained and weak for properties that do not need to be retained.

    weak properties are also nilled when the object is deallocated.

    The compiler will always assume that properties are readwrite so there is no need to declare then this way.

    @property (strong, nonatomic) PlayerData* playerData;
    @property (strong, nonatomic) MusicLayer* musicLayer;
    // Need use assign since strong is for objects only.
    @property (assign, nonatomic) bool isPowerUpAvailable;
    

提交回复
热议问题