tags:

views:

264

answers:

2

HI, i am using sample code from to handle Multiple NSUrlCOnnection from the link multiple url connection

when i use CustomURLConnection as NSObject inwhich i specified one Method as to enable

CustomURLConnection *connection = [[CustomURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES tag:tag]; 

through the following

 - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate   startImmediately:(BOOL)startImmediately tag:(NSString *)_tag

 {
connection = [[NSURLConnection alloc] initWithRequest:request delegate:delegate startImmediately:startImmediately];
self.tag = _tag;
return self;
  }

it gives error?

+1  A: 

I think you should try:

- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate   startImmediately:(BOOL)startImmediately tag:(NSString *)_tag
 {
    if(self = [super initWithRequest:request delegate:delegate])
    {   
       self.tag = _tag;
    }
    return self;
  }

(If I got you right and CustomURLConnection extends NSURLConnection and the code you pasted is CustomURLConnection's init code.)

Kai
senthilmuthu, see the original implementation here: http://blog.emmerinc.be/index.php/2009/03/02/custom-nsurlconnection-class-with-tag/
Costique
It appears that in his case CustomURLConnection inherits from NSObject and not NSURLConnection.
Felix
Yes, missed this in his description. So I think your answer is right.
Kai
+2  A: 

The problem is that there is no self. If CustomURLConnection inherits from NSObjectthe method should look like this:

- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate   startImmediately:(BOOL)startImmediately tag:(NSString *)_tag {
      if(self = [super init]) {
         self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:delegate startImmediately:startImmediately] autorelease];
         self.tag = _tag;
      }
      return self;
 }

You should also make sure that connection is an iVar of that Class and gets properly released in dealloc. Same for tagmake sure to add

 @synthesize tag,connection;

after @implementation and to declare a tag iVar and property.

Felix
I have edited the code. Make sure to synthesize both: tag and connection.
Felix