I have a method in which I pass 'id':
NSString *id = @"4bf58dd8d48988d181941735"; [self getNames:id];
This works fine, but when I use the "id" from the object passed within the segment:
NSString *id = _selectedStore._id; [self getNames:id];
I get an error message:
'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
What's happening?
Here he gets an error. My attempt (remember that I am new to this) is to take an array of Foursquare IDs, get the names, and then get photoUrl for the ID. If I delete all the code creating photoUrl (I noticed in the code), it works without crashing.
- (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 < [final count]; i++) { [[final objectAtIndex:i] addEntriesFromDictionary:newVen1]; } _arrayOfPlaces = final; NSLog(@"_arrayOfPlaces is %@",_arrayOfPlaces); [self.resultsVC reloadData]; } else { NSLog(@"%@",result); } }]; } else { NSLog(@"%@",result); } }]; } }
source share