I use NSXMLParser to parse the YouTube APIs and I get all the content I want and put it in a class called "Video". When I write to a class from parserDidEndElement and I end this video, I write a class in NSMutableArray . Then I NSLog the name of the video that was recorded in the array. This is different for each video. I use the addObject: method to add video to an array. However, when I use parserDidEndDocument , I use a for loop to read through the array, and all records have the same name value of the last added object! What's 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 = (video title)
I call this in the didEndDocument file:
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 video title added for all 19 videos)
iphone youtube-api nsmutablearray nsxmlparser
Chris
source share