If you expect (or want) something that matches this behavior:
t=0 add an operation to the queue. queueucount increments to 1 t=1 add an operation to the queue. queueucount increments to 2 t=2 add an operation to the queue. queueucount increments to 3 t=3 operation completes, queuecount decrements to 2 t=4 operation completes, queuecount decrements to 1 t=5 operation completes, queuecount decrements to 0 <your program gets notified that all operations are completed>
You should be aware that if several โshortโ operations are added to the queue, you can see this behavior instead (since operations start as part of the queue adding):
t=0 add an operation to the queue. queuecount == 1 t=1 operation completes, queuecount decrements to 0 <your program gets notified that all operations are completed> t=2 add an operation to the queue. queuecount == 1 t=3 operation completes, queuecount decrements to 0 <your program gets notified that all operations are completed> t=4 add an operation to the queue. queuecount == 1 t=5 operation completes, queuecount decrements to 0 <your program gets notified that all operations are completed>
In my project, I needed to know when the last operation was completed, after a large number of operations were added to the serial NSOperationQueue (i.e. maxConcurrentOperationCount = 1) and only when all of them were completed.
Googling. I found this expression from an Apple developer in response to the question: "Is the serial NSOPAQueue FIFO?" -
If all operations have the same priority (which does not change after the operation is added to the queue), and all operations are always - isReady == YES by the time they are placed in the operation queue, then the sequential NSOperationQueue is FIFO.
Chris Kane Cocoa Framework, Apple
In my case, you can find out when the last operation was added to the queue. Therefore, after adding the last operation, I add another operation to the lower priority queue, which does nothing but send a notification that the queue has been emptied. Given Appleโs operator, this ensures that only one notification is sent only after all operations are completed.
If operations are added in a way that the latter cannot be detected (that is, not deterministic), then I think you need to go with the KVO approaches mentioned above, with the addition of additional protection logic, to try to determine if additional operations can be added .
:)