title: NSArray objectAtIndex index 0 beyond bounds for empty array
body: <p>I'm working on someone else's app and and I'm getting this error:</p>
  
  <pre><code>'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 
   beyond bounds for empty array'
  </code></pre>
  
  <p>Xcode points to this line:</p>
  
  <pre><code> NSDictionary *geo = [response[0] objectForKey:@"geometry"];
  </code></pre>
  
  <p>Here's the full method:</p>
  
  <pre><code>- (void)loadLatLong {
  
  indx ++;
  if (indx == [datalist count]) {
      [self showMarker];
  //        self.alertView.hidden = true;
  //        [self setThreeQuarters];
      [self.progressbar setProgress:1.0 animated:YES];
      return;
  }
  PointClass *pt = datalist[indx];
  NSString *stPt = [pt.Location stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  NSString *str = [stPt stringByReplacingOccurrencesOfString:@" " withString:@"+"];
  NSString *url = [NSString stringWithFormat:@"https://maps.google.com/maps/api/geocode/json?address=%@&amp;sensor=false&amp;key=AIzaSyAoSBH8mBmeVp2HVx6vJrkTvl3bjRFiWag",str];
  
  NSURL *urlString = [NSURL URLWithString:url];
  AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  
  manager.responseSerializer = [AFJSONResponseSerializer serializer];
  manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
  [manager GET:[urlString absoluteString ]parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSArray *response = [responseObject objectForKey:@"results"];
      NSDictionary *geo = [response[0] objectForKey:@"geometry"];
      NSDictionary *location = [geo objectForKey:@"location"];
  
      pt.lat = [[location objectForKey:@"lat"] doubleValue];
      pt.lng = [[location objectForKey:@"lng"] doubleValue];
      datalist[indx] = pt;
      NSLog([NSString stringWithFormat:@"%%d \n"], indx);
      [self loadLatLong];
  
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  
    }];
  }
  </code></pre>
  
  <p>Can't figure out where to change the code.</p>
  
  <p>UPDATE:
  I want to add that it only crashes sometimes and sometimes it loads</p>