I am trying to create an array (state) of arrays (cities). Whenever I try to add an item to my City array, I get this error:
'NSInvalidArgumentException', reason: '*** + [NSMutableArray addObject:]: unrecognized selector sent to class 0x303097a0
My code is as follows. The line on which he makes mistakes is
[currentCities addObject:city]
I am sure that I have a memory management problem as I still do not understand all this. I was hoping someone could explain my mistake to me.
if (sqlite3_prepare_v2(db, sql, -1, &statement, NULL) == SQLITE_OK){
NSString *state = @"none";
NSMutableArray *currentCities = [NSMutableArray alloc];
while (sqlite3_step(statement) == SQLITE_ROW){
int primaryKey = sqlite3_column_int(statement, 0);
City *city = [[City alloc] initWithPrimaryKey:primaryKey database:db];
if (![state isEqualToString:city.state])
{
state = [[NSString alloc] initWithString:city.state];
[self.states addObject:currentCities];
currentCities = [NSMutableArray init];
}
[currentCities addObject:city];
[city release];
}
}
source
share