知识点
1 dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)
strcmp()
#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block)\
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}
#endif
- strcmp()是c语言的字符串比较函数. strcmp(s1,s2) 判断两个字符串s1和s2是否相同,相同返回true ,不同返回false
- dispatch_queue_get_label 传入DISPATCH_CURRENT_QUEUE_LABEL会返回当前队列.
- 如果是在主线程直接回调, 如果不是主线程, 异步回到主线程.
2
dispatch_get_current_queue
查看原文
Use the dispatch_get_current_queue function for debugging purposes or to test the identity of the current queu