Objective-C declared @property attributes (nonatomic, copy, strong, weak)

后端 未结 4 1270
攒了一身酷
攒了一身酷 2020-11-22 09:24

Can someone explain to me in detail when I must use each attribute: nonatomic, copy, strong, weak, and so on, for a decla

4条回答
  •  暖寄归人
    2020-11-22 09:57

    nonatomic property means @synthesized methods are not going to be generated threadsafe -- but this is much faster than the atomic property since extra checks are eliminated.

    strong is used with ARC and it basically helps you , by not having to worry about the retain count of an object. ARC automatically releases it for you when you are done with it.Using the keyword strong means that you own the object.

    weak ownership means that you don't own it and it just keeps track of the object till the object it was assigned to stays , as soon as the second object is released it loses is value. For eg. obj.a=objectB; is used and a has weak property , than its value will only be valid till objectB remains in memory.

    copy property is very well explained here

    strong,weak,retain,copy,assign are mutually exclusive so you can't use them on one single object... read the "Declared Properties " section

    hoping this helps you out a bit...

提交回复
热议问题