I’ve an array (tempList) populated with records read from a sqlite data source. I want to sort these records based on ‘region’. So I’ve set up the following NSMUtableArrays: _Asia, _Africa, _CentralAmerica, _southAmerica.
The method compiles without any errors. Where the ‘if’ statements return true, it executes the ‘addObject’ but the element is not added to the array.
- (void) sortIntoRegions: tempList
{
for (beans *arrayElement in tempList) {
NSLog(@"region: %@", arrayElement.region);
if ([arrayElement.region isEqualToString:@"Africa"]) {
[_africa addObject:arrayElement.name];
} else if ([arrayElement.region isEqualToString: @"Asia & South Pacific"]) {
[_asia addObject:arrayElement.name];
}
else if ([arrayElement.region isEqualToString: @"Central America"]) {
[_centralAmerica addObject:arrayElement];
} else if ([arrayElement.region isEqualToString: @"South America"]) {
[_southAmerica addObject:arrayElement];
}
}
}
I’m going to go out on a limb and guess that you have declared
_africa,_asia,_centralAmerica, and_southAmericato beNSMutableArray *, but you have not initialized them. That is, you have not written any code like this:Your instance variables are set to nil when your object is created. Sending a message (like
addObject:) to nil has no effect (and doesn’t print a warning or error message).