I would appreciate some help. I have used this before and it worked fine. I tried to use it in a new app and it breaks. I understand it is a problem with the index, but I can’t pin point it.
self.greensArray = [NSMutableArray array];
for (int i = 0; i < 26; ++i) {
[self.greensArray addObject:[NSMutableArray array]];
}
letterIndex =[[NSMutableArray alloc] init];
NSMutableArray *name = [searchViewArray valueForKey:@"meatName"];
for (int i = 0; i < [name count]; ++i) {
NSUInteger firstLetter = [ALPHA rangeOfString:[[name objectAtIndex:i ] substringToIndex:1]].location;
[self.greensArray insertObject:[NSMutableArray array] atIndex:i];
if (firstLetter != NSNotFound) {
[[self.greensArray objectAtIndex:firstLetter] addObject:[name objectAtIndex:i]];
}
char alphabet = [[name objectAtIndex:i] characterAtIndex:0];
NSString *uniChar = [NSString stringWithFormat:@"%C",alphabet];
if(![letterIndex containsObject:uniChar])
{
[letterIndex addObject:uniChar];
}
}
The problem was here: [self.greensArray insertObject:[NSMutableArray array] atIndex:i];
I don’t know why this worked in my first application, but this line of code added additional values to the greensArray. That threw off the integer / meatName count and made the whole app crash.