title: How to properly check if a UIImage is nil using the YouTube Api v3 in Swift?
body: <p>I'm having an issue checking if a <code>UIImage</code> is nil in order to display a <code>UIAlertViewController</code>.</p>
  
  <p>My app fetches playlists from a youtube channel. One of the playlist contains a video that has been removed by YouTube, and therefore does not contain a "thumbnails" key when fetching the playlist data.</p>
  
  <p>This is the code I've implemented to check whether there is a thumbnail image to display, otherwise display an Alert.</p>
  
  <pre><code>print("playlistVideos_ARRAY = \(self.playlistVideos_ARRAY)")
  
  print("startOfNextIndexForVideos = \(self.startOfNextIndexForVideos)")
  
  if let thumbnailImage: UIImage = UIImage(data: NSData(contentsOfURL: NSURL(string: ( ( ( (self.playlistVideos_ARRAY[self.startOfNextIndexForVideos] as! Dictionary&lt;NSObject, AnyObject&gt; )["snippet"] as! Dictionary&lt;NSObject, AnyObject&gt; )["thumbnails"] as! Dictionary&lt;NSObject, AnyObject&gt; )["high"] as! Dictionary&lt;NSObject, AnyObject&gt; )["url"] as! String )! )! )!
  {
       print("111111111")
       self.thumbnailOfVideo.append(thumbnailImage)
  }
  else
  {
       print("222222222")
  
       let message = UIAlertController(title: "Uh Oh!", message: "There is an issue with this playlist :(", preferredStyle: .Alert)
  
       let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
                          message.addAction(defaultAction)
  
       dispatch_async(dispatch_get_main_queue(), {
                              self.presentViewController(message, animated: true, completion: nil)
                          })
  }
  </code></pre>
  
  <p>However, it never outputs <code>222222222</code>. It always fails right at the if check with the following output:</p>
  
  <pre><code>playlistVideos_ARRAY = [{
      etag = "\"q5k97EMVGxODeKcDgp8gnMu79wM/Jl892aZsvFYpvjE5ENwTItH9cqQ\"";
      id = PLP2q8Ric9B9X6r8L2LA7xRwg0HNnKL3RLaooSkbmjTxo;
      kind = "youtube#playlistItem";
      snippet =     {
          channelId = UC5ltMmeC4YFaart1SSXdmAg;
          channelTitle = "Viet My Television";
          description = "This video is private.";
          playlistId = "PLxnnlv22Xcq34TNdsMxEIKvIHE_phd7XK";
          position = 0;
          publishedAt = "2016-03-16T18:51:39.000Z";
          resourceId =         {
              kind = "youtube#video";
              videoId = uPnWMZ1pbSc;
          };
          title = "Private video";
      };
  }]
  startOfNextIndexForVideos = 0
  fatal error: unexpectedly found nil while unwrapping an Optional value
  </code></pre>
  
  <p>What am I doing wrong in terms of checking this? Thanks.</p>
  
  <p><strong>EDIT:</strong>
  Here's an output of my <code>playlistVideos_ARRAY</code> fetched via a GET request that contains a valid playlist with a thumbnail of the associated video that hasn't been removed by YouTube:</p>
  
  <pre><code>playlistVideos_ARRAY = [{
      etag = "\"q5k97EMVGxODeKcDgp8gnMu79wM/U4OVbnjwS2bbU44Q1Hijy6-koAE\"";
      id = "PLP2q8Ric9B9VZXfc41HzRjprfOHpOYQd_SbLAuuxZVyw";
      kind = "youtube#playlistItem";
      snippet =     {
          channelId = UC5ltMmeC4YFaart1SSXdmAg;
          channelTitle = "Viet My Television";
          description = "";
          playlistId = PLxnnlv22Xcq0HpE242iwHh8IP78esU9sF;
          position = 0;
          publishedAt = "2016-02-15T23:25:20.000Z";
          resourceId =         {
              kind = "youtube#video";
              videoId = mIW5trLZJcM;
          };
          thumbnails =         {
              default =             {
                  height = 90;
                  url = "https://i.ytimg.com/vi/mIW5trLZJcM/default.jpg";
                  width = 120;
              };
              high =             {
                  height = 360;
                  url = "https://i.ytimg.com/vi/mIW5trLZJcM/hqdefault.jpg";
                  width = 480;
              };
              medium =             {
                  height = 180;
                  url = "https://i.ytimg.com/vi/mIW5trLZJcM/mqdefault.jpg";
                  width = 320;
              };
          };
          title = "talkshow chuong trinh hoi cho tet Binh Than o Miles Square Park";
      };
  }]
  </code></pre>