Graphics Programs Reference
In-Depth Information
Now that we have a plan, let's get to work. Create a new
NSObject
subclass named
RSSChannel
. A channel object needs to hold some metadata, an array of
RSSItem
in-
stances, and a pointer back to the previous parser delegate. In
RSSChannel.h
, add these
properties:
@interface RSSChannel : NSObject
@property (nonatomic, weak) id parentParserDelegate;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *infoString;
@property (nonatomic, readonly, strong) NSMutableArray *items;
@end
In
RSSChannel.m
, synthesize the properties and override
init
.
@implementation RSSChannel
@synthesize items, title, infoString, parentParserDelegate;
- (id)init
{
self = [super init];
if (self) {
// Create the container for the RSSItems this channel has;
// we'll create the RSSItem class shortly.
items = [[NSMutableArray alloc] init];
}
return self;
}
@end
Back in
ListViewController.h
, add an instance variable to hold an
RSSChannel
object and have the class conform to the
NSXMLParserDelegate
protocol.
// a forward declaration; we'll import the header in the .m
@class RSSChannel;
@interface ListViewController : UITableViewController
<NSXMLParserDelegate>
{
NSURLConnection *connection;
NSMutableData *xmlData;
RSSChannel *channel;
In
ListViewController.m
, implement an
NSXMLParserDelegate
method to
catch the start of a
channel
element. Also, at the top of the file, import the header for
RSSChannel
.
#import "RSSChannel.h"
@implementation ListViewController
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI