title: Function that executes after multiple completion block has finished
body: <p>I have a funciton that I would like to only execute IF the two completion block has completed (And no way to tell which one to finish first). Below is my attempt that works. However, it is very messy and if I there are three or more completion block that I want to wait for, I would have flags everywhere. I was wondering if there is a prettier way of doing it.</p>
  
  <pre><code>class TestClass: UIViewController {
      var blockOneComplete = false
      var blockTwoComplete = false
  
      func blockOneDownloadImageDescription(completion:()-&gt;Void) {
          downloadAsyncWithCompletion {
              blockOneComplete = true 
              if self.blockTwoComplete == true {
                  self.allDataDownloadCompleted()
              } else {
                  // Do nothing and wait for block Two to complete
              }
          }
      }
  
      func blockTwoDownloadImageData(completion:()-&gt;Void) {
          downloadAsyncWithCompletion {
              blockTwoComplete = true 
              if self.blockOneComplete == true {
                  self.allDataDownloadCompleted()
              } else {
                  // Do nothing and wait for block One to complete
              }
          }
      }
  
      func allDataDownloadComplete() {
          // Execute this funciton after all Async Download has complete
      }
  }
  </code></pre>
  
  <p>-- Update with final result -- 
  Turns out that what was outlined in this website was exactly what I needed 
  <a href="http://commandshift.co.uk/blog/2014/03/19/using-dispatch-groups-to-wait-for-multiple-web-services/" rel="nofollow">Using dispatch groups to wait for multiple web services</a></p>
  
  <p>I believe this was not a duplicate of the SO question mentioned in the comment because the final solution included dispatch_group_enter and dispatch_group_leave </p>