Canceling Operations

Back in the sample app, select the row called Operation Queue-Concurrent. Quickly tap the Cancel button at the top of the table while the operations are running. Notice that nothing appears to happen after the Cancel button has been tapped, and the operations will finish. When the Cancel button is touched, the operation queue is instructed to cancel all outstanding operations:

- (IBAction)cancelButtonTouched:(id)sender{    [self.processingQueue cancelAllOperations];}

The reason this does not work as expected is because Cancelled is just a flag on an operation object—the logic of the operation must dictate how the operation behaves when it is canceled. The call to cancelAllOperations: dutifully ...

Get iOS Components and Frameworks: Understanding the Advanced Features of the iOS SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.