title: How to download image from URL Swift
body: <p>So I am trying to download images from url link and then trying to add them to an array of downloaded images but running into trouble.</p>
  
  <p><strong>I have</strong> searched stackoverflow and related sites, but could not find similar issue.</p>
  
  <p>There are two kinds of images that I am downloading.</p>
  
  <p>Example of 1st type is : <a href="http://img.youtube.com/vi/7lC3UZtLa6Y/0.jpg" rel="nofollow">http://img.youtube.com/vi/7lC3UZtLa6Y/0.jpg</a></p>
  
  <p>Example of 2nd type is : <a href="http://master.dextra.xyz/_uploads/photos/image_111.webp" rel="nofollow">http://master.dextra.xyz/_uploads/photos/image_111.webp</a>    </p>
  
  <p>Please click on both to see the difference</p>
  
  <p>I have no trouble downloading the first type, simply by using the following code. But as you can see the second url link would download itself on clicking and hence I get nil when extracting it</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
  
   // Downloading image 1
              let data = NSData(contentsOfURL: NSURL(string: "http://img.youtube.com/vi/7lC3UZtLa6Y/0.jpg")!)
              self.downloadedImages.append(UIImage(data: data!)!)
  // No problem downloading above image, also shows up in my app
  
        // Downloading image 2
          let data = NSData(contentsOfURL: NSURL(string: "http://master.dextra.xyz/_uploads/photos/image_111.webp")!)
              self.downloadedImages.append(UIImage(data: data!)!)
          // getting nil in UIImage(data: data!), although it says that data is around 300000 bytes.
  
          dispatch_async(dispatch_get_main_queue(), {
          // Updating UI
         });
      }
  </code></pre>
  
  <p>So, how can I download images of second type? It downloads it successfully. But cannot access it  because it stores in computer somewhere, I am not sure about it though</p>
  
  <p>Any help would be appreciated. Thanks</p>