Wait for async method before segue
<p>I have a button and when I press it I´m calling an Async function:</p>

<pre><code>func check(url : String){
        let url = NSURL(string: url)
        print("Checking")
        dispatch_async(dispatch_get_main_queue(), {
            let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
                if error == nil {
                    self.isWorking = true
                }
                else{
                    self.isWorking = false
                    }
                }
            }
            task.resume()
        })
    }
</code></pre>

<p>So when I press my button I do the following:</p>

<pre><code>override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!){
        let web = segue.destinationViewController as! ViewController()

        check(url)

        dispatch_async(dispatch_get_main_queue(), {
              if (isWorking){ 
                   // Do stuff
              }
      })
}
</code></pre>

<p>The problem is that isWorking is called before the check method is completed. </p>

<p>How can I make sure that check is completed before I make my check for isWorking?</p>