Graphics Programs Reference
In-Depth Information
Create BNRConnection , the actor, as a new NSObject subclass. BNRConnection
needs instance variables and properties to hold the connection, request, and callback.
Modify BNRConnection.h to look like this:
@interface BNRConnection : NSObject
<NSURLConnectionDelegate, NSURLConnectionDataDelegate>
{
NSURLConnection *internalConnection;
NSMutableData *container;
}
- (id)initWithRequest:(NSURLRequest *)req;
@property (nonatomic, copy) NSURLRequest *request;
@property (nonatomic, copy) void (^completionBlock)(id obj, NSError *err);
@property (nonatomic, strong) id <NSXMLParserDelegate> xmlRootObject;
- (void)start;
@end
For every request the BNRFeedStore makes, it will create an instance of BNRCon-
nection . An instance of this class is a one-shot deal: it runs, it calls back, and then it is
destroyed. The next time a request is made, another instance of BNRConnection will
be created. The store's responsibility here is to pass on the appropriate data (the request
and callback block) to the BNRConnection so that it can function. In other words, a
store object becomes a middle man: it takes the simple demands of a controller and sends
its BNRConnection minions off to carry out the work.
In addition to the request and callback, the store will provide an xmlRootObject to the
BNRConnection . This object will be the object that eventually gets returned to the con-
troller. In this case, the xmlRootObject will be an instance of RSSChannel . The
Search WWH ::




Custom Search