Graphics Programs Reference
In-Depth Information
BNRConnection class is pretty handy - you can use that in any application. In fact, that
very same class is in a number of applications that are currently on the App Store.)
Another request
Now that we have BNRConnection and a store object, adding new requests for the
store to handle is really straight-forward. Let's have the BNRFeedStore fetch the top
songs from iTunes . First, we need to make a minor change to the RSSChannel and
RSSItem classes because Apple's RSS feed uses a different element name ( entry ) to
identify items in their RSS feed. In RSSChannel.m , modify pars-
er:didStartElement:namespaceURI:qualifiedName:attributes: to
create an RSSItem when it encounters the entry element.
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqual:@"title"]) {
currentString = [[NSMutableString alloc] init];
[self setTitle:currentString];
}
else if ([elementName isEqual:@"description"]) {
currentString = [[NSMutableString alloc] init];
[self setInfoString:currentString];
} else if ([elementName isEqual:@"item"]
|| [elementName isEqual:@"entry"]) {
RSSItem *entry = [[RSSItem alloc] init];
[entry setParentParserDelegate:self];
[parser setDelegate:entry];
[items addObject:entry];
}
}
Then in RSSItem.m , have the RSSItem return control to the channel when it ends an
entry element.
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
currentString = nil;
if ([elementName isEqual:@"item"]
Search WWH ::




Custom Search