eric.mitchell
eric.mitchell

Reputation: 8855

NSArray SIGABRT

NSString* year = [self.years objectAtIndex:[indexPath section]];

//get algorithms for that year
NSArray* algorithmSection = [self.algorithmNames objectForKey:year];

NSLog(@"%@", indexPath);

//get specific algorithm based on that row
cell.textLabel.text = [algorithmSection objectAtIndex:indexPath.row];

return cell;

For whatever reason, when I compile this, I get a SIGABRT error. It happens on the

cell.textLabel.text

line. Error:

2011-08-29 19:26:21.273 xxxxxxxxxxx[1431:b303] 2 indexes [0, 0]

2011-08-29 19:26:21.274 xxxxxxxxxxxxx[1431:b303] -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x4ba2370

2011-08-29 19:26:21.277 xxxxxxxxx[1431:b303] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x4ba2370' terminate called throwing an exception

Upvotes: 0

Views: 508

Answers (3)

Hermann Klecker
Hermann Klecker

Reputation: 14068

As lemnar and mjisawai said, you are actually dealing with an NSDictionary.

The way to fix this depends on the context of your app. If you happen to receive either, NSArrays or NSDictionary objects then you may determine this by texting the object's class.

i.e.

if ([algorithmSection isKindOfClass:[NSArray class]]) {
  ...
} else if ([algorithmSection isKindOfClass:[NSDictionary class]]) {
  ...
}

Upvotes: 1

mjisrawi
mjisrawi

Reputation: 7936

Could the object at key "year" in your algorithmSections dictionary be a dictionary instead of an array? That's what it looks like is happening here.

Upvotes: 0

lemnar
lemnar

Reputation: 4053

Your algorithmSection variable, which your code expects to be an NSArray, is actually an NSDictionary, which does not respond to the selector -objectAtIndex:.

Upvotes: 1

Related Questions