Skip to content

Instantly share code, notes, and snippets.

@isutton
Created November 27, 2013 16:02
Show Gist options
  • Save isutton/7678143 to your computer and use it in GitHub Desktop.
Save isutton/7678143 to your computer and use it in GitHub Desktop.
NSOperation dependency creep
NSMutableDictionary *context = [NSMutableDictionary dictionary];
// Adds information in context under the key "fromOp1"
Op1 *op1 = [[Op1 alloc] initWithContext:context];
// Consumes "fromOp1" from context and add info under the key "fromOp2"
Op2 *op2 = [[Op2 alloc] initWithContext:context];
[op2 addDependency:op1];
// Adds info in context under the key "fromOp3"
Op3 *op3 = [[Op3 alloc] initWithContext:context];
// Consumes "fromOp3" from context and add info under the key "fromOp4"
Op4 *op4 = [[Op4 alloc] initWithContext:context];
[op4 addDependency:op3];
// Add info under the key "fromOp5"
Op5 *op5 = [[Op5 alloc] initWithContext:context];
[op5 addDependencies:@[op2, op4]];
// Consumes "fromOp2", "fromOp4" and "fromOp5" from context.
Op6 *op6 = [[Op6 alloc] initWithContext:context];
[op6 addDependency:op5];
@isutton
Copy link
Author

isutton commented Nov 27, 2013

The reason "context" is being sent to all the operations is that the results are needed in each step of the dependency chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment