title: Downloading JSON data fails at NSHTTPURLResponse
body: <p>I am trying to get a JSON file from a URL and return the contents using Swift. However, the code fails at the line <code>let httpResponse = response as! NSHTTPURLResponse</code>  in the following code. I get an exception at this line and Xcode goes into debug mode.</p>
  
  <pre><code>class func downloadJSONFile()-&gt;AnyObject
      {
          let requestURL: NSURL = NSURL(string: "http://www.learnswiftonline.com/Samples/subway.json")!
          let urlRequest: NSMutableURLRequest = NSMutableURLRequest(URL: requestURL)
          let session = NSURLSession.sharedSession()
          var json:AnyObject = ""
          let task = session.dataTaskWithRequest(urlRequest) {
              (data, response, error) -&gt; Void in
  
              let httpResponse = response as! NSHTTPURLResponse
              let statusCode = httpResponse.statusCode
  
              if (statusCode == 200) {
  
                  do{
                      json = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments)
  
                  }catch {
                      print("Error with Json: \(error)")
  
                  }
  
              }
  
          }
  
          task.resume()
  
          return json
      }
  </code></pre>
  
  <p>How can I fix this?</p>