How to use dispatch_async_f?

大城市里の小女人 提交于 2020-02-03 05:02:28

问题


The function that I want queued takes no parameters. What do I pass in as paramContext? Passing in NULL generates the compile error "Invalid use of void expression". I do not want to add a parameter to my function just to make it compile - how do I make this work?

Mac OS X Snowleopard, Xcode 3.2.6 with Objective-C


回答1:


You need to wrap the function somehow. The easiest way is actually to use dispatch_async() instead, as in

dispatch_async(queue, ^{ myFunc() });



回答2:


While you can just pass 0/NULL for the context argument, dispatch_async_f() takes void (*)(void*) as the function parameter, you can't pass it a function that takes no arguments.

You need to either change your function to take a void* parameter:

void func(void*) {}

... or, if you can't, wrap it:

void orig(void) {}
void wrapper(void*) { orig(); }

// ...
dispatch_async_f(queue, 0, &wrapper);


来源:https://stackoverflow.com/questions/9320142/how-to-use-dispatch-async-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!