title: Declaration/definition of variables locations in ObjectiveC?
body: <p>Ever since starting to work on iOS apps and objective C I've been really puzzled by the different locations where one could be declaring and defining variables. On one hand we have the traditional C approach, on the other we have the new ObjectiveC directives that add OO on top of that. Could you folks helps me understand the best practice and situations where I'd want to use these locations for my variables and perhaps correct my present understanding?</p>
  
  <p>Here's a sample class (.h and .m):</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  
  // 1) What do I declare here?
  
  @interface SampleClass : NSObject
  {
      // 2) ivar declarations
      // Pretty much never used?
  }
  
  // 3) class-specific method / property declarations
  
  @end
  </code></pre>
  
  <p>and</p>
  
  <pre><code>#import "SampleClass.h"
  
  // 4) what goes here?
  
  @interface SampleClass()
  
  // 5) private interface, can define private methods and properties here
  
  @end
  
  @implementation SampleClass
  {
      // 6) define ivars
  }
  
  // 7) define methods and synthesize properties from both public and private
  //    interfaces
  
  @end
  </code></pre>
  
  <ul>
  <li>My understanding of 1 and 4 is that those are C-style file-based declarations and definitions that have no understanding whatsoever of the concept of class, and thus have to be used exactly how they would be used in C. I've seen them used for implementing static variable-based singletons before. Are there other convenient uses I'm missing?</li>
  <li>My take from working with iOS is that ivars have been alost completely phased out outside of the @synthesize directive and thus can be mostly ignored. Is that the case?</li>
  <li>Regarding 5: why would I ever want to declare methods in private interfaces? My private class methods seem to compile just fine without a declaration in the interface. Is it mostly for readability?</li>
  </ul>
  
  <p>Thanks a bunch, folks!</p>