Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Properties are just a convenient way to access the data. So when you are declaring the property @property (nonatomic, retain) SomeType* someObject; this means that during access there would be synthesized 2 methods: </p> <p>getter: </p> <pre><code>-(SomeType*) someObject { return someObject; } </code></pre> <p>setter</p> <pre><code>-(void) setSomeObject:(SomeType*) obj { [someObject release]; someObject = [obj retain]; } </code></pre> <p>So the main difference between properties and ivars is that properties dynamically creating the setter/getter methods (and you can override them). But when you're writing someObject = new_val, you're just copying the reference to the memory location. No additional work is done there except one assembly instruction.</p> <p>There is one more thing to mention: atomic and nonatomic. With atomic, the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, regardless of setter activity on any other thread. That is, if thread A is in the middle of the getter while thread B calls the setter, an actual viable value -- an autoreleased object, most likely -- will be returned to the caller in A.</p> <p>In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than atomic.</p> <p>Edit: so if you have some variable, that is accessed from different threads or/and some additional work has to be done (e.g. retain, raise some flags ...), then your choice is property. But sometimes you have a variable, that is accessed very often and access via property can lead to a big overhead, because processor has to perform much more operations to synthesize and call method. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload