title: NSData init?(contentsOf url: URL) migration from Swift 2 to Swift 3
body: <p>New to iOS/Swift. I am trying to migrate a project (that simply fetches contents from a URL via the <code>NSData init()</code> method) from Swift 2 to Swift 3. The original code looks like this:</p>
  
  <pre><code>let loadedImageData = NSData(contentsOfURL: imageURL)
              dispatch_async(dispatch_get_main_queue()) {
                  if imageURL == user.profileImageURL {
                      if let imageData = loadedImageData  {
                          self.profileImageView?.image = UIImage(data: imageData)
                      }
                  }
              }
  </code></pre>
  
  <p>Swift 3 migration:</p>
  
  <pre><code> let loadedImageData = NSData(contentsOf: imageURL as URL)
              DispatchQueue.main.async {
                  if imageURL == user.profileImageURL {
                      if let imageData = loadedImageData  {
                          self.profileImageView?.image = UIImage(data: imageData as Data)
                      }
                  }
              }
  </code></pre>
  
  <p>I am not sure as to why we need to cast the <code>NSData</code> return value as a <code>URL</code> and then cast that return again to a <code>Data</code> type while loading the image within Swift 3. We are assigning the raw data to a variable <code>loadedImageData</code> in both the version. Why the casting then? It seems that the <code>UIImage init()</code> method needs a data object within Swift 3. However for Swift 2 there is no casting for the same. Why is that?</p>
  
  <p>Thanks for the help.</p>