How to cast blocks to and from void *

ε祈祈猫儿з 提交于 2019-11-30 11:35:25

Here's a small example. I think that the problem with your code is that you are trying to use __bridge_transfer with a void * which isn't memory managed with ARC:

void takesBlock(void *asPointer)
{
    void (^asBlock)() = (__bridge typeof asBlock) asPointer;

    asBlock();
}

int main()
{
    @autoreleasepool {
        takesBlock((__bridge void *)[^{
            NSLog(@"Hello World!");
        } copy]);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!