Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While Daniel's answer is correct, I think it misses an important point. Namely:</p> <blockquote> <p>I find that using properties instead of plain old ivars just takes too much code and I don't really see the benefits if you're comfortable with memory management.</p> </blockquote> <p>The benefits are consistency; consistent memory management and consistent behavior.</p> <p>Notably, these two lines of code can actually have <em>extremely different</em> behavior at runtime:</p> <pre><code>iVar = [foo retain]; self.iVar = foo; </code></pre> <p>The first is a direct setting of the instance variable and there will be no change notifications. The second goes through the setter and, thus, preserves any subclass customizations upon set <em>and <strong>ensures that any observers of the property are notified of the change</em></strong>.</p> <p>If you are using ivars directly throughout your code (internally to the class -- if you are using ivars of an instance directly from <em>outside</em> that instance, well... any contractor working on your codebase should double their rates ;), then you must either also handle change notification propagation manually (typically by calling <code>willChangeValueForKey:</code>/<code>didChangeValueForKey</code>) <em>or</em> explicitly engineer your application to avoid use of mechanisms that rely upon Key-Value Observation.</p> <p>You say "takes too much code". I don't see that; in the above two lines of code, the dot syntax is fewer characters. Even calling the setter method using traditional syntax would be less code.</p> <p>And do not discount the value in centralizing memory management; one accidental omission in a myriad of call sites and crash city.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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