title: Swift 2 : NSData(contentsOfURL:url) returning nil
body: <p>I have a webpage address which contains a JSON file. I'm trying to access the JSON file as NSDictionary in Swift 2. Every time I call  <code>NSData(contentsOfURL:url!)</code> where <code>url</code> is type of <code>NSURL?</code>, it returns <code>nil</code>. I'm using Xcode 7 Beta, and the project was first made in Xcode 6.</p>
  
  <p>The following code is causing the problem.</p>
  
  <pre><code>let url = NSURL(string:myurl) // myurl is the webpage address.
  let data = NSData(contentsOfURL:url!) // the bit that returns nil
  // data is set to nil
  // I would perform NSJSONSerialization.JSONObjectWithData later.
  </code></pre>
  
  <p>What is confusing me is that when I try the exact same thing when I type the same code in Terminal using <code>swift</code>, the constant <code>data</code> is  not set to nil. I have tried rebooting the Mac, and it didn't work. I tried reinstalling Xcode, and it didn't work. </p>
  
  <p>This is what happens when I type the following code to the Terminal, using <code>swift</code> keyword. </p>
  
  <pre><code>$&gt; swift
  ......
  Welcome to Apple Swift version 2.0 (700.0.38.1 700.0.53). Type :help for assistance. 
  
  1&gt; import Foundation
  2&gt; var urlstr = "http://mywebsiteaddress/jsonfile.json"
  3&gt; var nsurl = NSURL(string:urlstr)
  nsurl: NSURL? = "http://mywebsiteaddress/jsonfile.json"{
      ObjectiveC.NSObject = {...}
  }
  4&gt; var nsdata = NSData(contentsOfURL:nsurl!)
  nsdata: NSData? = 5925 bytes {
      ObjectiveC.NSObject = {...}
  }
  5&gt; print(nsdata)
  Optional(&lt;Some Values..........&gt;)
  </code></pre>
  
  <p>When I try in the Terminal it definitely worked. Can anyone help me solve the problem??</p>