title: IOS App crash: [__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
body: <p>I have a method I pass an 'id' into here:</p>
  
  <pre><code>NSString *id = @"4bf58dd8d48988d181941735";
  [self getNames:id];
  </code></pre>
  
  <p>This works fine, but when I use the 'id' from an object passed within the segue:</p>
  
  <pre><code>NSString *id = _selectedStore._id;
  [self getNames:id];
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
  </code></pre>
  
  <p>What's going on?</p>
  
  <p>Here's where it's getting the error. My attempt (keep in mind i'm new at this) is to take an array of Foursquare id's, get the names and then get the photoUrl for the id's. If I remove all code that creates the photoUrl (i've noted in the code) it runs without crashing.</p>
  
  <pre><code>- (void)getNames {
      NSMutableArray *final = [[NSMutableArray alloc] init];
      for (SearchVenue *object in self.venues) {
      [Foursquare2 venueGetDetail:object._id  callback:^(BOOL success, id result){
              if (success) {
                  NSDictionary *dic = result;
                  NSArray *venue = [dic valueForKeyPath:@"response.venue"];
                  self.venueDetail = venue;                
                  NSMutableDictionary *newVen = [NSMutableDictionary dictionary];
                  [newVen setValue:[self.venueDetail valueForKey:@"name"] forKey:@"name"];
                  [final addObject:newVen];
                      [Foursquare2 venueGetPhotos:object._id limit:nil offset:nil callback:^(BOOL success, id result){
                          if (success) {
  
                              NSDictionary *dic = result;
                              NSArray *photos = [dic valueForKeyPath:@"response.photos"];
                              self.venuePhotos = photos;
  
                               //works when removed from here...
                              NSString *prefix = [[self.venuePhotos valueForKeyPath:@"items.prefix"] objectAtIndex:0];
                              NSString *size = @"100x100";
                              NSString *suffix = [[self.venuePhotos valueForKeyPath:@"items.suffix"] objectAtIndex:0];
                              NSArray *myStrings = [NSArray arrayWithObjects:prefix,size,suffix, nil];
                              NSString *photoUrl = [myStrings componentsJoinedByString:@"" ];
                              //...to here
  
                              NSMutableDictionary *newVen1 = [NSMutableDictionary dictionary];
                                  [newVen1 setValue:photoUrl forKey:@"photoUrl"];
                              for(int i = 0; i &lt; [final count]; i++) {
                                 [[final objectAtIndex:i] addEntriesFromDictionary:newVen1];
                              }
                              _arrayOfPlaces = final;
                              NSLog(@"_arrayOfPlaces is %@",_arrayOfPlaces);
                              [self.resultsVC reloadData];
                          } else {
                              NSLog(@"%@",result);
                          }
                      }];
              } else {
                  NSLog(@"%@",result);
                }
          }];
      }
  }
  </code></pre>