title: Make sure function runs on main thread only
body: <p>How can I make sure that my function is run only on the main thread? It updates UI elements.</p>
  
  <p>Is a function like this considered 'bad'? </p>
  
  <pre><code>-(void)updateSomethingOnMainThread {
      if ( ![[NSThread currentThread] isEqual:[NSThread mainThread]] )
          [self performSelectorOnMainThread:_cmd withObject:nil waitUntilDone:NO];
      else {
          // Do stuff on main thread
      }
  }
  </code></pre>
  
  <p>I wrote it like this to avoid having a second function, initially I had it like this:</p>
  
  <pre><code>-(void)updateSomethingOnMainThread_real {
      // Do stuff on main thread
  }
  
  -(void)updateSomethingOnMainThread {
      [self performSelectorOnMainThread:@selector(updateSomethingOnMainThread_real) withObject:nil waitUntilDone:NO];
  }
  </code></pre>