I would like to execute code sequentially in an NSOperation.
This can be easily done by instantiating NSInvocationOperation, for example in a controller of mine I have:
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *prepare = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(prepare)
object:nil];
NSInvocationOperation *load = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(loadData)
object:nil];
[load addDependency:prepare];
This works perfectly, and most of all I can keep dependency between operations. But as you can see I had to create methods encapsulating the operation itself.
I would like instead to instantiate the invocation as a fragment of code, and keep dependency.
Therefore my view controller would be clean for never again used methods.
I saw there is a ^block option but seems that dependency is not maintained.
thanks
You should be able to add dependencies with any subclass of
NSOperation. In your case you probably wantNSBlockOperation: