title: Continue with code after URLSession.shared.uploadTask is completed
body: <p>I am trying to communicate with Swift to a php-website using the command "uploadTask". The site is sending Data back, which is working well. The result from the website is stored in the variable "answer". But how can I actually use "answer" AFTER the uploadTask.resume() was done?</p>
  
  <p>When running the file, it always prints:
  "One" then "three" then "two".</p>
  
  <p>I know that I could do things with "answer" right where the section "print("two")" is. And at many examples right there the command    "DispatchQueue.main.async { ... }" is used. But I explicitly want to finish the uploadTask and then continue with some more calculations.</p>
  
  <pre><code>   func contactPHP() {
  
      print("One")
  
      let url = "http://....php" // website to contact
      let dataString = "password=12345" // starting POST
      let urlNS = NSURL(string: url)
      var request = URLRequest(url: urlNS! as URL)
      request.httpMethod = "POST"
      let dataD = dataString.data(using: .utf8) // convert to utf8 string
  
      URLSession.shared.uploadTask(with: request, from: dataD)
      {
          (data, response, error) in
          if error != nil {
              print(error.debugDescription)
          } else {
              let answer = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)!
              print("Two")
          }
          }.resume()  // Starting the dataTask
  
    print("Three")
  
   // Do anything here with "answer"
  
  }
  
  extension NSMutableData {
      func appendString(string: String) {
          let data = string.data(using: String.Encoding.utf8, allowLossyConversion: true)
          append(data!)
      }
  }
  </code></pre>
  
  <p>I already tried it with a completion handler. But this does not work either. This also gives me "One", "Four", "Two", "Three"</p>
  
  <pre><code>func test(request: URLRequest, dataD: Data?, completion: @escaping (NSString) -&gt; ()) {
      URLSession.shared.uploadTask(with: request, from: dataD)
      {
          (data, response, error) in
          if error != nil {
              print(error.debugDescription)
          } else {
              let answer = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)!
              print("Two")
              completion(answer)
          }
          }.resume()  // Starting the dataTask
      }
  
  let blubb = test(request: request, dataD: dataD) { (data) in
      print("Three")
  }
  
  print("Four")
  </code></pre>