I'm trying to add an NSString to an NSMutableArray (which will hold only NSStrings). I'm not getting any errors, but when I query the array's count
, it returns zero, indicating that it didn't add the value. Here's my code (its getting some XML, which is definitely 100% working):
// get an array of genres for this game
NSArray *genreList = [self getAllItems:@"//genre" fileName:[NSURL URLWithString:queryURL]];
int numberOfGenres = [genreList count];
NSLog(@"This game has %u genres", numberOfGenres);
This NSLog reports correctly, the number of entries in the XML result, usually between 1-5.
// put the genre names from that array into the current game's object
if (numberOfGenres > 0) {
for (int i = 0; i < numberOfGenres; i++) {
NSString *currentGenreName = [NSString stringWithString:[[genreList objectAtIndex:i] objectForKey:@"name"]];
[currentGame.gameGenres addObject: currentGenreName];
NSLog(@"I added a genre to %@, called %@.", currentGame.gameName, currentGenreName);
}
}
This NSLog also reports correctly, with the game's title, and the of that in the XML tree.
// save current game to game list
NSLog(@"I'm about to save %@ to the array, with its %u genres", currentGame.gameName, [currentGame.gameGenres count]);
[_listOfGamesReturnedFromSearch addObject:currentGame];
This last NSLog always reports the number of genres as zero. If I query the _listOfGamesReturnedFromSearch
array later, it saved the other properties fine (name), but the genres count is zero – it didn't save them for some reason.
Any ideas?