I figured this should be easy, but I am having problems writing a simple class level category method that takes a block for an argument. Here is my example while trying to add a class method to NSAutoreleasePool.
#import <Foundation/Foundation.h>
@interface NSAutoreleasePool (MyBlockAdditions)
+ (void)forWork: (void (^)(void))work;
@end
#import "NSAutoreleasePool+MetaSkillsAdditions.h"
@implementation NSAutoreleasePool (MyBlockAdditions)
+ (void)forWork: (void (^)(void))work {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
work();
[pool release];
}
@end
[NSAutoreleasePool forWork:^{
...
}];
I am currently getting this error now. I am likely doing something dumb.
2011-03-05 16:17:49.150 MyApp[28100:40b] +[NSAutoreleasePool forWork:]: unrecognized selector sent to class 0xb20598 2011-03-05 16:17:49.154 MyApp[28100:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSAutoreleasePool forWork:]: unrecognized selector sent to class 0xb20598'
Have you included the category header file (
NSAutoreleasePool+MetaSkillsAdditions.h) to the file containing the code that calls the new method?