1
votes

This is how I initialize my NSMutablearray. I copy the content of cityList into cityArray. Both are NSMutableArray. FYI, I declared the'cityArray' using extern.

cityArray = [[NSMutableArray alloc] init];

[cityArray addObjectsFromArray:cityList];

Then, in other method in another class, I tried to to add one more object into 'cityArray' This is how I do it. But it keep crashing when it run this line of code.

NSString *allCities = @"All Cities";
[[cityArray valueForKey:@"cityName"] addObject:allCities];

This is from the console '[__NSArrayI addObject:]: unrecognized selector sent to instance 0x6292de0''.

But if I test it with setvalue:forkey:, it works but that is not what I want. I want the new data to be added into the bottom of the list.

1
why [[cityArray valueForKey:@"cityName"] addObject:allCities]; ? You can use [cityArray addObject:allCities]; - iMOBDEV
because in city array also cityID property which I will need it later.. - sicKo

1 Answers

0
votes

An NSArray doesn't implement valueForKey:. Your want either an NSDictionary or use objectAtIndex:.

Your second section of code should read:

NSString *allCities = @"All Cities";
[cityArray addObject:allCities];