Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems filling an NSMutableArray with data retrieved by an NSXMLParser
    primarykey
    data
    text
    <p>I'm working on my first somewhat serious iOS app and I'm new to Xcode, iOS, and Objective-C. I've followed along with, and done a the first few assignments from Stanford's iOS class on iTunesU. Aside from that I have no experience.</p> <p>Anyways, I'm using an NSXMLParser to parse an XML file retrieved from the internet, and then I'm trying to create UGStory objects to represent some of the data and add them to an NSMutableArray.</p> <p>EDIT: I've made some changes to the code and updated it here. Now I am sure there is a problem with my NSXMLParser functions. Now when the program executes I end up with 30 objects in the array, but when I inspect the array every object says "Out of Scope" and "Summary Unavailable".</p> <p>Also, this data is being used to populate a split view controller. Titles go in the masterview, links are used to fill the detailview. But after this executes there is only one thing in the master; "News @ Ultimate-Guitar.Com"</p> <p>That is the first text enclosed by headers and at this point the header is yet to be encountered. Because of this I should have no UGStory objects so I'm confused by how this cell is being set. Also everything in the array is "Out of Scope" so where is the controller getting this data from? The controller does nothing more than create a UGFeedReader and send it the parseFeed message.</p> <pre><code>#import "UGFeedReader.h" @implementation UGFeedReader @synthesize currentTag = _currentTag; @synthesize stories = _stories; @synthesize read = _read; @synthesize i = _i; - (void)parseFeed { NSURL* ugFeed = [NSURL URLWithString:@"http://www.ultimate-guitar.com/modules/rss/news.xml.php"]; NSXMLParser* feedParser = [[NSXMLParser alloc]initWithContentsOfURL:ugFeed]; _stories = [[NSMutableArray alloc] initWithCapacity:10]; _i = 0; _read = NO; [feedParser setDelegate:self]; [feedParser parse]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict { if ([elementName isEqualToString:@"item"]) { _read = YES; UGStory* temp = [[UGStory alloc] init]; [_stories addObject:temp]; } return; } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if (!_currentTag) { _currentTag = [[NSMutableString alloc] init]; } [_currentTag appendString:string]; } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if (_read == YES) { if ([elementName isEqualToString:@"title"]) { UGStory* temp = [_stories objectAtIndex:_i]; temp.title = _currentTag; } if ([elementName isEqualToString:@"link"]) { UGStory* temp = [_stories objectAtIndex:_i]; temp.url = [NSURL URLWithString:_currentTag]; _read = NO; _i++; } } return; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload