title: Does dispatch_async(dispatch_get_main_queue(), ^{...}); wait until done?
body: <p>I have a scenario in my app, where I want to do some time consuming task which consists of some data processing as well as UI update, in a method. My method looks like this,</p>
  
  <pre><code>- (void)doCalculationsAndUpdateUIs {
  
      // DATA PROCESSING 1
      // UI UPDATE 1
  
      // DATA PROCESSING 2
      // UI UPDATE 2
  
      // DATA PROCESSING 3
      // UI UPDATE 3
  } 
  </code></pre>
  
  <p>As it is time consuming I wanted to do the data processing on the background thread, using,</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, NULL), ^{
  </code></pre>
  
  <p>But as both data processing and UI updates are in the same method, I wanted to move only the UI updates in main thread using,</p>
  
  <pre><code>dispatch_async(dispatch_get_main_queue(), ^{
  </code></pre>
  
  <p>Finally my method looks like this,</p>
  
  <pre><code>- (void)doCalculationsAndUpdateUIs {
  
      // DATA PROCESSING 1 
      dispatch_async(dispatch_get_main_queue(), ^{
          // UI UPDATE 1
      });
  
      /* I expect the control to come here after UI UPDATE 1 */
  
      // DATA PROCESSING 2
      dispatch_async(dispatch_get_main_queue(), ^{
          // UI UPDATE 2
      });
  
      /* I expect the control to come here after UI UPDATE 2 */
  
      // DATA PROCESSING 3
      dispatch_async(dispatch_get_main_queue(), ^{
          // UI UPDATE 3
      });
  }
  </code></pre>
  
  <p>Does this really work? Is this really a good practice? What is the best way to achieve this?</p>
  
  <p>P.S. All these three operations are interrelated to each other.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> Sorry guys. I have <strong>missed a line in the above code</strong>. My actual code looks like this.</p>
  
  <pre><code>- (void)doCalculationsAndUpdateUIs {
  
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  
          // DATA PROCESSING 1 
          dispatch_async(dispatch_get_main_queue(), ^{
              // UI UPDATE 1
          });
  
          /* I expect the control to come here after UI UPDATE 1 */
  
          // DATA PROCESSING 2
          dispatch_async(dispatch_get_main_queue(), ^{
              // UI UPDATE 2
          });
  
          /* I expect the control to come here after UI UPDATE 2 */
  
          // DATA PROCESSING 3
          dispatch_async(dispatch_get_main_queue(), ^{
              // UI UPDATE 3
          });
      });
  }
  </code></pre>
  
  <p>Once again, I really apologize for the confusion.</p>