title: UIImage Download Returning nil and Crashing App (Swift)
body: <p>I have an image url string:</p>
  
  <pre><code>var remoteImage: String = "http://server.com/wall-e.jpg"
  </code></pre>
  
  <p>I then construct a UIImage to download on a <strong>separate thread</strong> using Grand Central Dispatch with <code>remoteImage</code> as the <code>NSURL</code> string parameter:</p>
  
  <pre><code>let getImage = UIImage(data: NSData(contentsOfURL: NSURL(string: remoteImage)!)!)
  </code></pre>
  
  <p>When it is finished and I return back to the main thread, I have it save internally:</p>
  
  <pre><code>UIImageJPEGRepresentation(getImage, 1.0).writeToFile(imagePath, atomically: true)
  </code></pre>
  
  <p>On Wi-fi and LTE it downloads fine, but when testing edge cases such as on an Edge network (no pun intended), I <strong>inconsistently</strong> get the error:</p>
  
  <pre><code>fatal error: unexpectedly found nil while unwrapping an Optional value
  </code></pre>
  
  <p>Now I thought I would be safe by making sure that it wasn't <code>nil</code> by adding in:</p>
  
  <pre><code>if getImage != nil { ... }
  </code></pre>
  
  <p>But it didn't seem to make a difference. It still gets the error and highlights the <code>let getImage</code> as written above. What am I doing wrong here? Should I be checking nil in a different manner or method? </p>