为动态类方法解析将块强制转换为void *

|
+(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);
        ...
我在最后一行收到错误,因为noteFactoryBLOCK强制转换为void *,而ARC不允许这样做。目前有什么方法可以完成我想要的吗?我想要一个可以在运行时传递给class_addMethod的IMP。 编辑
    IMP myIMP = imp_implementationWithBlock(objc_unretainedPointer(noteFactoryBLOCK));
这行是警告我而不是错误-
Semantic Issue: Passing \'objc_objectptr_t\' (aka \'const void *\') to parameter of type \'void *\' discards qualifiers
    
已邀请:
        我不想这么说,但是在这种情况下,您可能只需要删除const。
IMP myIMP = imp_implementationWithBlock((void*)objc_unretainedPointer(noteFactoryBLOCK));
不过那很丑。     

要回复问题请先登录注册