jverkoey/nimbus — Issue #147: NIOperation blocks should pass op as an argument
Author: gurgeous
Created: 2012-01-23 19:23:33+00:00
State: open

It seems minor, but that would be a big improvement in the API. Why? As currently designed, the API requires blocks like this:

```objc
NINetworkRequestOperation *op = [[NINetworkRequestOperation alloc] initWithURL:[NSURL URLWithString:@"http://www.apple.com"]];
op.didFinishBlock = ^(void) {
NSLog(@"got some data %@", op.processedObject);
};
[[Nimbus networkOperationQueue] addOperation:op];
```

ARC doesn't like this and throws up a "retain cycle" warning because we're using op inside the block. The workarounds are quite ugly if you want to target iOS 4. Stuff like:

```objc
NINetworkRequestOperation *op = [[NINetworkRequestOperation alloc] initWithURL:[NSURL URLWithString:@"http://www.apple.com"]];
__unsafe_unretained NINetworkRequestOperation *copy;
op.didFinishBlock = ^(void) {
NSLog(@"got some data %@", copy.processedObject);
};
[[Nimbus networkOperationQueue] addOperation:op];
```

Anyway, I think we should just pass the current operation as an argument to the blocks. The BlocksKit project uses this design and it works quite well. Thanks!