NSOperationQueue
manages its internal queue of NSOperation
s. An NSOperation will only be removed from the queue after it is canceled or finished.
Note that if an NSOperation
is cancelled, it merely sets the appropriate flags within the NSOperation
object to mark it as such - The implementation of the NSOperation
is responsible for checking if it is cancelled and marking itself finished accordingly. An operation that has not started should check if it is cancelled when it starts and return immediately after marking itself finished. A long-running operation which is executing would need to periodically check if it is cancelled and handle that state in a similar manner.
It also makes sense to do this check before executing destructive code or code that will mutate data, such as saving or deleting a managed object from core data.
See https://developer.apple.com/reference/foundation/nsoperation/1411672-cancel?language=objc