title: IOS Grand Central Dispatch with callback method
body: <p>I haven't used GCD or much threading in my apps but I've run into a situation where I need to run a method or two off another thread.  Once this method completes I need to call another method using the main thread from a callback.  I've been searching around to see how to detect when a thread has finished the operation but still not too clear on the subject.  </p>
  
  <p>I created a test app and just used the viewDidLoad method for a quick example.</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
          NSLog(@"viewDidLoad called");
          sleep(5);  // simulating a thread being tied up for 5 seconds
  
  
          dispatch_async(dispatch_get_main_queue(), ^{
              [self callbackMethod];  // method called after above thread has completed running
          });
  
      });
  
  
  }
  </code></pre>
  
  <p>Will this example work for what I'm trying to do? When running the application it appears that the callback method is called after the sleep(5) finishes.  Is this the proper way of handling this situation or am I way off course?</p>