Giuseppe Lanza Giuseppe Lanza - 5 months ago 48
iOS Question

NSOperation cancel and NSOperationQueue

i would like to understand what is the correct behavior for an nsoperation subclass.
I have my subclasses with different isReady conditions. Yes, i check in the code if the operation is cancelled and i act in consequence. This is great while the operation is in execution. It stops its task, sets the finished to true and it gets deleted from the queue. but what about its dependencies? they are not yet executing, so they stay in the NSOperationQueue in cancelled state for ever.

Should i set ready = true for cancelled operations so the queue will call the start method that will set in executing and immediately finish the task setting finished to yes?

Thanks for the help.

Answer

The dependent operation will be executed. No matter a is cancelled or not.

You should set operation.finished==true at the final state to make NSOperationQueue removes the operation.

You should set .ready==true whenever it's ready to begin the operation.

In life cycle of operation, you should frequently check .cancelled whenever .cancelled == true, you should stop operation and set .finished == true.

Comments