For iOS NSOperationQueue, when will the queue remove the operation block? For my project I use MKNetworkKit to manage network request actions, as you know request/response is async operation, will the queue remove the operation once the request sent out? Or it will wait the response then remove it from the queue? Anyone who knows please share and discuss together, thanks in advance.
An operation block should inherit from NSOperation, which is an abstract class. There are some ways to remove the block from the operation queue.
1) You implement the -(void)main method, when it finishes it will be removed from the queue. 2) You can also implement isFinished method to return an instance var that you can manipulate to finish your block before finishing the -(void)main. For this you should also change the KVO values so the operation queue knows when to call the isFnished, like this:
[self willChangeValueForKey:@"isFinished"];
finished = YES;
[self didChangeValueForKey:@"isFinished"];
And in your isFinished:
- (BOOL)isFinished {
return finished;
}