title: Checking and Remedying Null Objects Efficiently
body: <p>Has anyone found a more efficient way of checking if a variable is nil, then instantiating it?  I know the classic way is to write:</p>
  
  <pre><code>if (myObject == nil) {
      //instantiate and do other stuff
  }
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>if (!myobect) { 
      //do stuff
  }
  </code></pre>
  
  <p>Which seems too boiler-plate-esque for my liking, especially if I have to do it many times.</p>
  
  <p>EDIT: Having had a stroke of inspiration, would something like this work?</p>
  
  <pre><code>-(id)instantiateIfObjectIsNull:(id)object withClass:(Class*)class {
      if (object == nil) {
          object = [[Class alloc]init];
      }
      return object;
  }
  </code></pre>