title: Swift wait until dataTaskWithRequest has finished to call the return
body: <p>I am new to Swift and I have a question regarding synchronous calls. 
  I would like to make a synchronous call to dataTaskWithRequest, so that the return method is called once the dataTaskWithRequest is finished. Here is my code:</p>
  
  <pre><code>private func sendRequest (request: NSURLRequest) -&gt; NSData{
      let session = NSURLSession.sharedSession()
      var dataReceived: NSData = NSData ()
      let task = session.dataTaskWithRequest(request) { data, response, error in
          if error != nil{
              print("Error -&gt; \(error)")
              return
          }
      dataReceived = data!
      }
      task.resume()
      return dataReceived
  }
  </code></pre>
  
  <p>What is the best way to do it? I have tried with a completion handler but I am not able to do it.</p>
  
  <p>Thank you very much in advance for the help.</p>