NSOperationQueue should have an addBlockOperationWithBlock: method
| Originator: | doug | ||
| Number: | rdar://11734824 | Date Originated: | |
| Status: | Open | Resolved: | |
| Product: | iPhone SDK | Product Version: | 6.0 |
| Classification: | Enhancement | Reproducible: | N/A |
23-Jun-2012 10:02 PM Doug Russell:
Summary:
Currently NSOperationQueue has a method for adding block operations:
- (void)addOperationWithBlock:(void (^)(void))block;
which offers no reasonable way to access the operation thats created from within the block which makes testing for canceled unreasonable.
NSOperationQueue should either change addOperationWithBlock: to include the block operation or add a new method like the following:
- (void)addBlockOperationWithBlock:(void (^)(NSBlockOperation *op))block
{
NSBlockOperation *blockOperation = [NSBlockOperation new];
__weak NSBlockOperation *weakBlockOperation = blockOperation;
[blockOperation addExecutionBlock:^{
block(weakBlockOperation);
}];
[self addOperation:blockOperation];
}
Here's an implementation done via a category
http://cl.ly/231K170D3G453c0E0T0K
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!