Is there a way to wrap an ObjectiveC block into function pointer?

前端 未结 4 1833
忘了有多久
忘了有多久 2020-12-10 05:51

I have to provide a C-style callback for a specific C library in an iOS app. The callback has no void *userData or something similar. So I am not able to loop i

4条回答
  •  鱼传尺愫
    2020-12-10 06:12

    If your block needs context information, and the callback does not offer any context, I'm afraid the answer is a clear no. Blocks have to store context information somewhere, so you will never be able to cast such a block into a no-arguments function pointer.

    A carefully designed global variable approach is probably the best solution in this case.

提交回复
热议问题