Reputation: 4789
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)
Upvotes: 2
Views: 531
Reputation: 16827
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];
}];
}
Upvotes: 3