Is it right if I cancel an NSInvocationOperation
inside the operation?
example:
.h file:
//defined in the interface
NSInvocationOperation *op1;
NSOperationQueue *loadQueue;
.m file:
-(id)init{
op1 = [NSInvocationOperation new];
loadQueue = [NSOperationQueue new];
}
-(void)downloadData{
op1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadServerResponse:) object:newerRequest];
[loadQueue addOperation:op1];
}
Now I have a method to download data from the server. I added a condition to check if there is an error. If so I'm cancelling that operation inside the method and calling back the same method upon retrieving the new login token.
- (void)loadServerResponse{
if(server_error){
[op1 cancel];
//fetch login token again
[self downloadData];
return;
}
Am I doing anything wrong?