I read how parameters can be parameterized in Objective-C. With the parameters readonly, assign and copy everything is clear. With nonatomic - not really (sort of like an analog of volatile in Java?), But with retain really bad. I can not understand in which case I need to use exactly retain? In the topic of memory management, it is written that "requires increasing the reference count." That is, if our retain is in the advertisement, then each time it is accessed, the reference count is necessarily increased (it is not clear why this is necessary then)?
1 answer
retain
, in contrast to copy
does not copy an object when accessing a property, but increases the usage count and returns the same object (as if an object reference). This is necessary if the object is large or does not make sense to copy it. For example, objects like UIView
, UIViewController
, UIWindow
.
The nonatomic keyword means that when generating implementations of a setter and a getter ( @synthesize
), the compiler will not insert locks to correctly access the property from different threads. That is, nonatomic means "thread safe". In most cases, nonatomic is preferred, since the setter and getter work faster.
- it turns out, retain - transfer by reference, copy - by value. - angry
- Yes, that is right. - y0prst
|