Graphics Programs Reference
In-Depth Information
|| [elementName isEqual:@"entry"]) {
[parser setDelegate:parentParserDelegate];
}
}
Now we will add another request that a controller can ask the BNRFeedStore to carry
out. In BNRFeedStore.h , declare a new method.
@interface BNRFeedStore : NSObject
+ (BNRFeedStore *)sharedStore;
- (void)fetchTopSongs:(int)count
withCompletion:(void (^)(RSSChannel *obj, NSError *err))block;
- (void)fetchRSSFeedWithCompletion:(void (^)(RSSChannel *obj, NSError *err))block;
@end
The implementation of this method will be really easy now that we have the format of the
store determined and the BNRConnection class ready to go. The two differences
between fetchTopSongs:withCompletion: and fetchRSSFeedWithCom-
pletion: are that fetchTopSongs:withCompletion: will take an argument
supplied by the controller to determine how many songs to fetch and will access a differ-
ent web service. Implement this method in BNRFeedStore.m .
- (void)fetchTopSongs:(int)count
withCompletion:(void (^)(RSSChannel *obj, NSError *err))block
{
// Prepare a request URL, including the argument from the controller
NSString *requestString = [NSString stringWithFormat:
@"http://itunes.apple.com/us/rss/topsongs/limit=%d/xml", count];
NSURL *url = [NSURL URLWithString:requestString];
// Set up the connection as normal
NSURLRequest *req = [NSURLRequest requestWithURL:url];
RSSChannel *channel = [[RSSChannel alloc] init];
BNRConnection *connection = [[BNRConnection alloc] initWithRequest:req];
[connection setCompletionBlock:block];
[connection setXmlRootObject:channel];
[connection start];
}
Now we have a store object that returns two different RSS feeds, and the controller
doesn't have to know any of the details about how they are fetched. Let's give the user a
way to switch between the two feeds. In ListViewController.h , declare a new
enum for the feed types and an instance variable to hold on to the current feed type.
typedef enum {
ListViewControllerRSSTypeBNR,
ListViewControllerRSSTypeApple
} ListViewControllerRSSType;
Search WWH ::




Custom Search