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.
An
NSArraydoesn’t implementvalueForKey:. Your want either anNSDictionaryor useobjectAtIndex:.Your second section of code should read: