title: Reliable methods which require specific thread
body: <p>Given a method which must be executed on main thread:</p>
  
  <pre><code>    -(void)methodRequiringMainThread{
  
       int a=1;
  
      }
  </code></pre>
  
  <p>And a caller to it:</p>
  
  <pre><code>    -(void)callerToMethod{
  
        if(![NSThread isMainThread]){
          dispatch_sync(dispatch_get_main_queue(), ^{[self methodRequiringMainThread]}); 
        } else {
         [self methodRequiringMainThread];
        }
  
  }
  </code></pre>
  
  <p>What is the best practice for insuring that the the method is called on main thread?</p>
  
  <ol>
  <li>Annotate in interface comment and hope all callers check for main
  thread and dispatch as necessary (as above). </li>
  <li>Wrap the private method in a
  public method which simply checks for main thread and dispatches the
  private method as necessary. </li>
  <li>Insert an NSAssert in the called method</li>
  </ol>
  
  <p>I've seen issues relying on #1 + #3, and I don't like it because you can't test for a caller which winds up on another thread rarely. </p>
  
  <p>I also don't like it because there is no specific functionality for revealing this requirement to the caller in the method signature - its (an important) semi-secret.</p>
  
  <p>I'd prefer to use #2 (or just wrap the contents in a block internally and check), because it guarantees the main thread regardless of the caller.</p>
  
  <p>UIKit doesn't seem to do any explicit checking or exposure either, which is strange at this point. Seems like there should be some sort of functionality built-in, even if its only internal to XCode, which communicates and/or guarantees the thread.</p>