+(BOOL)resolveClassMethod:(SEL)aSel {
NSString *lString = NSStringFromSelector(aSel);
if ([self validateLetterAndAccidental:lString]) {
id (^noteFactoryBLOCK)(id) = ^(id aSelf) {
return [self noteWithString:lString];
};
IMP lIMP = imp_implementationWithBlock(noteFactoryBLOCK);
...
I get an error at the last line because noteFactoryBLOCK is cast to a void* and ARC disallows that. Is there currently a way to accomplish what I want? I would like an IMP that I can pass to class_addMethod at runtime.
EDIT
IMP myIMP = imp_implementationWithBlock(objc_unretainedPointer(noteFactoryBLOCK));
This line give me a warning instead of an error - Semantic Issue: Passing 'objc_objectptr_t' (aka 'const void *') to parameter of type 'void *' discards qualifiers
I hate to say it but you might just have to cast away the const in this case.
IMP myIMP = imp_implementationWithBlock((void*)objc_unretainedPointer(noteFactoryBLOCK));
That is pretty ugly though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With