This blog offers a good solution for handling multiple NSURLConnections: create a custom class called "CustomURLConnection" that has an additional tag property.
http://blog.emmerinc.be/index.php/2009/03/02/custom-nsurlconnection-class-with-tag/
http://blog.emmerinc.be/index.php/2009/03/15/multiple-async-nsurlconnections-example/
Basically, he just added the tag property to the existing NSURLConnection:
CustomURLConnection.m
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate startImmediately:(BOOL)startImmediately tag:(NSString*)tag { self = [super initWithRequest:request delegate:delegate startImmediately:startImmediately]; if (self) { self.tag = tag; } return self; }
then, in the normal NSURLConnection boot mode, you can do:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { //Log the connection's tag CustomURLConnection *ttttag = (CustomURLConnection *)connection; // **HERE** NSLog(@"%@", ttttag.tag); NSMutableData *dataForConnection = [self dataForConnection:(CustomURLConnection*)connection]; [connection release]; }
So, I have a problem. The way I see it, this is how things are:
- I create a "connection tag +"
- The first code snippet I posted above creates a regular “no
tag ”, which ultimately will call the usual NSURLConnection methods, such as connectionDidFinishLoading . What happens to tag at this moment? - In the
connectionDidFinishLoading method, I can return the connection back to the "connection +" tag, and then find the information about the lost tags that was dropped. How?
Maybe I'm just confusing, but it seems that the tag was dropped when it starts the normal NSURLConnection path. But then, dropping it as a subclass, I can again restore the tag property. Where did he live / go on average?
Can someone with a better understanding of inheritance explain this to me?
source share