有什么区别
dispatch_async_f
和
dispatch_async
在 iOS 中?
最佳答案
使用这个异步 block 的主要原因是有后台任务。
dispatch_async:
通过使用此 block ,您可以异步运行代码块
例如。
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates can be done only on main thread
});
});
dispatch_async_f:
无论异步任务中的 block 如何,您都可以将自定义函数放在后台执行。
例如:
void mainFunc(void) {} // your function
void callingFuncForAsyncTask(void*) { mainFunc(); } // new function which takes arguments for calling inside async_f
dispatch_async_f(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), 0, &callingFuncForAsyncTask);
更多信息和参数详情请引用: https://developer.apple.com/reference/dispatch/1452834-dispatch_async_f
关于ios - dispatch_async_f 和 dispatch_async 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38656809/