title: Swift: If let statement failing to handle empty array
body: <p>I have an application that is using the Foursquare API to download JSON data. I am using <code>NSURLSession</code> and the <code>dataTaskWithRequest</code> with completion block method to fetch the data. I am getting the data fine but sometimes a nested array named <code>groups</code> can be empty. And when I am parsing through the JSON like below, for some reason my conditional statement is not handling the empty array like I am expecting it should. Instead of evaluating the array as empty and proceeding to the "else" portion of the <code>if let...else</code> statement if instead throughs a runtime error stating: <code>index 0 beyond bounds of empty array</code></p>
  
  <pre><code>if let response: NSDictionary = data["response"] as? [String: AnyObject],
              groups: NSArray = response["groups"] as? NSArray,
                          // Error here \|/ (sometimes groups array is empty)
              dic: NSDictionary = groups[0] as? NSDictionary,
              items: NSArray = dic["items"] as! NSArray {
  
  }
  
  else {
  
      // Never gets here. Why?
      // IF the groups array is empty, then the if let should return 
      // false and drop down to the else block, right?
  }
  </code></pre>
  
  <p>I am relatively new to Swift, can someone tell me why this is happening and what I can do to fix this? Thanks</p>