I use an NSXMLParser to parse YouTube's API and I get all the content I want and put it into a class called Video. When I am writing to the class from inside parserDidEndElement and I end that video I write the class to an NSMutableArray. Then I NSLog the title of the video that was logged into the array. This is different for each video. I use the addObject: method to add videos to the array. However when I use parserDidEndDocument I use a for loop to read through the array and all of the entries have the same title value of the last object added! What is going on here?
I call this in didEndElement:
Video *tempVideo = [Video new];
NSString *title = @"";
tempVideo = [allVideos objectAtIndex:[allVideos count]-1];
title = tempVideo.videoTitle;
NSLog(@"1videoTitle = %@", title);
It returns for each element 1videoTitle = (the videos title)
I call this in didEndDocument:
int i;
Video *tempVideo = [Video new];
NSString *title = @"";
for(i=0;i<[allVideos count];i++){
tempVideo = [allVideos objectAtIndex:i];
title = tempVideo.videoTitle;
NSLog(@"videoTitle = %@", title);
}
It returns for each element videoTitle = (the last added videos title for all 19 of the videos)