iOS - 主线程调度在应用中的小技巧
1 2 3 4 5 6 7 8 9 10 11 12 13
| #pragma mark - 宏定义 #ifndef dispatch_queue_async_safe #define dispatch_queue_async_safe(queue, block)\ if (dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL) == dispatch_queue_get_label(queue)) {\ block();\ } else {\ dispatch_async(queue, block);\ } #endif
#ifndef dispatch_main_async_safe #define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block) #endif
|
dispatch_queue_get_label:返回创建队列时为队列指定的标签。
END