2
votes

I have a subclass of NSOperation which send a cancel request over a network. I want to cancel operation only if the request was successful :


// overrider cancel of NSOperation
-(void)cancel{
 [NSURLConnection sendAsynchronousRequest:request 
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
       [super cancel];
    }];
}

Will this cause any retain cycle or something ? Do I need a weak Super (I am using ARC)

1

1 Answers

3
votes

It won't create a retain cycle, your instance doesn't hold a strong reference to the completion block. However I would prefer not calling the super implementation like this, maybe something like this

-(void)cancelAfterRequest 
{
    [NSURLConnection sendAsynchronousRequest:request 
                                       queue:[NSOperationQueue mainQueue]
                           completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
         [self cancel];
    }];
}