“Converting” a function pointer to a block in objective-C

后端 未结 3 2157
星月不相逢
星月不相逢 2021-02-20 07:48

I\'m doing some Interop from Mono C# to Obj-C and ran into this problem. The C# code needs to pass a callback - which it does with a function pointer. I can get the function poi

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 08:34

    why not just have a simple function

    typedef void (*DummyAction)(char * result);
    typedef void (^DummyBlock)(char * result);
    
    DummyBlock functionToBlock(DummyAction func) {
        return [[^(char * result) {
                     func(result);
                 } copy] autorelease];
    }
    

提交回复
热议问题