title: Where to declare a static variable in objective-c?
body: <p>I did some research about static variables in objective-c and I found people declare static variables in different places which made me really confused.</p>
  
  <ol>
  <li><p>For the following code, can I put <code>static NSUInteger counter;</code>outside of the implementation? (Right after my #import "xxx.h")</p></li>
  <li><p>Can I put <code>static NSUInteger counter;</code>inside of +initialize class method?</p></li>
  <li><p>Can I put <code>static NSUInteger counter;</code> into a instance method?</p></li>
  <li><p>Most importantly, what are the differences and how to choose where to declare them?</p></li>
  </ol>
  
  <p>Thanks!</p>
  
  <pre><code>@implementation MyClass
  
  static NSUInteger counter;
  
  +(void)initialize {
      if (self == [MyClass class]) {
          counter = 0;
      }
  }
  
  @end
  </code></pre>