I have two NSURLConnections. The second one depends on the content of the first, so handling the data received from the connection will be different for the two connections.
I'm just picking up Objective-C and I would like to know what the proper way to implement the delegates is.
Right now I'm using:
NSURL *url=[NSURL URLWithString:feedURL];
NSURLRequest *urlR=[[[NSURLRequest alloc] initWithURL:url] autorelease];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:urlR delegate:self];
I don't want to use self as the delegate, how do I define two connections with different delegates?
NSURLConnection *c1 = [[NSURLConnection alloc] initWithRequest:url delegate:handle1];
NSURLConnection *c2 = [[NSURLConnection alloc] initWithRequest:url delegate:handle2];
How would do i create handle1 and handle2 as implementations? Or interfaces? I don't really get how you would do this.
Any help would be awesome.
Thanks, Brian Gianforcaro
Ben, while your info was helpful It didn't fully answer the question I asked.
I finally figured out how to setup my own delegates, which was what I was really asking.
I implemented it like so:
@interface DownloadDelegate : NSObject
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
@end
@implementation DownloadDelegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
}
@end
We use the delegate like so:
DownloadDelegate *dd = [DownloadDelegate alloc];
NSURLConnection *c2 = [[NSURLConnection alloc] initWithRequest:url delegate:dd];
Hope that helps anybody in the same position, and thanks again Ben for your help.
Thanks,
Brian Gianforcaro
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With