I would like to add functions by creating a category for Objective-C Blocks.
__block int (^aBlock)(int) = ^int( int n ){
if( n <= 1 ) return n;
return
Dave DeLong is right, you cannot add a category on a class that you cannot see, but as blocks are subclasses of NSBlock
adding:
@interface NSBlock : NSObject
@end
Now you can 'see' NSBlock
and add a category on it, e.g.:
@interface NSBlock (map)
- (NSArray *)mapTo:(NSArray *)array;
@end
@implementation NSBlock (map)
- (NSArray *)mapTo:(NSArray *)array
{
...
}
@end
Still probably not the best thing to do in code that is actually used in production...