title: Waiting until the task finishes
body: <p>How could I make my code wait until the task in DispatchQueue finishes? Does it need any CompletionHandler or something?</p>
  
  <pre><code>func myFunction() {
      var a: Int?
  
      DispatchQueue.main.async {
          var b: Int = 3
          a = b
      }
  
      // wait until the task finishes, then print 
  
      print(a) // - this will contain nil, of course, because it
               // will execute before the code above
  
  }
  </code></pre>
  
  <p>I'm using Xcode 8.2 and writing in Swift 3.</p>