How can I check开发者_开发知识库 to see if an object in an NSMutableArray is nil or not without getting the error index .. beyond bounds for empty array
? I receive the error using the following code:
if (![self.sortedArray objectAtIndex:[alphabet indexOfObject:[NSString stringWithFormat:@"%c", (char) [letter characterAtIndex:0]]]]) {
NSMutableArray *arr = [NSMutableArray arrayWithObject:countryDict];
[self.sortedArray addObject:arr];
}
else {
[[self.sortedArray objectAtIndex:[alphabet indexOfObject:[NSString stringWithFormat:@"%c", (char) [letter characterAtIndex:0]]]] addObject:countryDict];
}
Simply check that the index you are using is lower than [array count]
;)
精彩评论