You cannot stop right away using everything that Apple provides with NSOperation
. You can use -[cancel]
, as other people suggested, but the current operation will be performed until completion. One way to get closer to using -[isCancelled]
inside your operation and sprinkle it throughout the code (especially in long loops). Sort of:
- (void)main { // do a little work if ([self isCancelled]) { return; } // do a little more work if ([self isCancelled]) { return; } }
So you will stop soon.
If you really want to stop the flow, you may need to study signal processing. A threaded example is shown here. By sending a custom signal to a specific stream, you can somehow end this stream. It will be a lot more work, and probably a lot more problems than it costs.
source share