When does NSOperationQueue remove an operation from a queue?

I need to know that when an NSOperationQueue removes an operation from a queue? I have an NSOperationQueue that has an NSOperation list. At what point NSOperationQueue remove the operation from the queue?

  • After starting the operation? OR
  • After completing or canceling the operation?

Since I need a notification when all operations in NSOperationQueue complete. For this, I called this link

+9
ios nsoperation nsoperationqueue
source share
2 answers

According to Apple Developer Reference

The operation queue executes its NSOperation objects, which are queued based on their priority and availability. After adding operations to the queue, the operation remains in its queue until it announces the completion of its task.

Thus, NSOperationQueue deletes the operation after it is completed.

Source - https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSOperationQueue_class/Reference/Reference.html

+8
source share

NSOperationQueue manages its internal NSOperation s queue. An NSOperation operation will not be removed from the queue until it is canceled or completed.

Note that if NSOperation is canceled, it simply sets the appropriate flags in the NSOperation object to mark it as such. The implementation of NSOperation is responsible for verifying its cancellation and the corresponding labeling. An operation that did not start should check whether it was canceled at startup and return immediately after the marking itself is completed. A lengthy operation that is performed should periodically check whether it is canceled, and handle this state in the same way.

It also makes sense to perform this check before executing the destructive code or code that will modify the data, for example, save or delete a managed object from the main data.

See https://developer.apple.com/reference/foundation/nsoperation/1411672-cancel?language=objc.

+6
source share

All Articles