title: NSURLSession timeout
body: <p>I have a function where I make a request to get a <code>JSON</code>.</p>
  
  <pre><code>let request = NSMutableURLRequest(URL: NSURL(string: path)!)
  let session = NSURLSession.sharedSession()
  
  session.configuration.timeoutIntervalForRequest = 5
  session.configuration.timeoutIntervalForResource = 5
  
  let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -&gt; Void in
       let json:JSON = JSON(data: data!)
       onCompletion(json, error)
  })
  task.resume()
  </code></pre>
  
  <p>This works, but I´m having issues with the timeout. If the request takes more than 5 seconds I want to cancel the operation. Any ideas how to do this?</p>
  
  <p>The call can take more than 5 seconds but it stills fires and the timeout does not do anything. Do I have to do anything if the timeout is fired?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>        let request = NSMutableURLRequest(URL: NSURL(string: path)!)
  
          let urlconfig = NSURLSessionConfiguration.defaultSessionConfiguration()
          urlconfig.timeoutIntervalForRequest = 5
          urlconfig.timeoutIntervalForResource = 5
          let session = NSURLSession(configuration: urlconfig, delegate: self, delegateQueue: nil)
  
          let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -&gt; Void in
              let json:JSON = JSON(data: data!)
              onCompletion(json, error)
          })
          task.resume()
  </code></pre>