title: Lazy Loading in Objective-C - Should I call the setter from within the getter?
body: <p>This is a small detail but everytime I lazy load something I get caught up on it. Are both of these methods acceptable? Is either better? Assume that the variable has the retain property.</p>
  
  <p>Method #1</p>
  
  <pre><code>(AnObject *)theObject{
      if (theObject == nil){
          theObject = [[AnObject createAnAutoreleasedObject] retain];
      }
      return theObject;
  }
  </code></pre>
  
  <p>Method #2</p>
  
  <pre><code>(AnObject *)theObject{
      if (theObject == nil){
          self.theObject = [AnObject createAnAutoreleasedObject];
      }
      return theObject;
  }
  </code></pre>
  
  <p>First, I'm not sure if it's OK to access another accessor function within an accessor (don't see why not, though). But it seems like setting the class variable without going through the setter could be equally bad if the setter does something special (or if the property is changed to something besides retain and the getter isn't checked).</p>