Created
September 10, 2012 07:29
-
-
Save ksm/3689424 to your computer and use it in GitHub Desktop.
NSOperation cancel pattern and retain cycle avoidance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Source: Building Concurrent User Interfaces on iOS | |
WWDC2012 Session 211 by Andy Matuschak | |
*/ | |
NSOperationQueue *queue = [[NSOperation alloc] init]; | |
NSBlockOperation *op = [[NSBlockOperation alloc] init]; | |
__weak NSBlockOperation *weakOp = op; | |
[op addExecutionBlock:^{ | |
for (int i = 0; i < 10000; i++) { | |
if ([weakOp isCancelled]) break; | |
processData(data[i]); | |
} | |
}]; | |
[queue addOperation:op]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment