Graphics Programs Reference
In-Depth Information
The code in the block that gets executed if there is an error looks just like the code in
connection:didFailWithError: .
This, of course, is intentional. We are not changing what Nerdfeed does - only how it
does it. ListViewController will no longer manage the details of the NSURLCon-
nection . In MVCS, controllers don't do that kind of work, store objects do.
ListViewController now flows exceptionally well: it says, “Fetch these entries, and
then do this if this happens or that if that happens.” All of this code is in one place instead
of strewn over a number of methods. The code is easy to read, easy to maintain, and easy
to debug.
With this code in place, you can clean up ListViewController . In
ListViewController.m , you can delete the following methods. (The bodies of the
methods have been omitted to save trees.)
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
...
}
- (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)data
{
[xmlData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)conn
{
...
}
- (void)connection:(NSURLConnection *)conn
didFailWithError:(NSError *)error
{
...
}
In ListViewController.h , you can delete the instance variables connection and
xmlData , as well as remove the protocol declaration for NSXMLParserDelegate .
@interface ListViewController : UITableViewController <NSXMLParserDelegate>
{
NSURLConnection *connection;
NSMutableData *xmlData;
RSSChannel *channel;
 
Search WWH ::




Custom Search