title: Wait for NSURLSessionTask to complete
body: <p>I have a simple NSURLConnection task</p>
  
  <pre><code>let task = NSURLSession.sharedSession().dataTaskWithURL(url1!) { data, response, error in
      if error != nil {
          println(error)
          return
      }
  
      let parser = NSXMLParser(data: data)
      parser.delegate = self
      if parser.parse() {
          println(self.results)
      }
  }
  task.resume()
  
  if task.state == NSURLSessionTaskState.Completed {
      println("task is done")
  }
  </code></pre>
  
  <p>But instead of an if statement, which is just passed right over since the task is still running when it hits that code, I wanted a way for code to run once "task" is completed. I can't seem to find anything in the literature.</p>