保證執行緒在主執行緒執行

Crazy巴旦木發表於2018-08-08

主執行緒同步佇列 #define dispatch_main_sync_safe(block)
if ([NSThread isMainThread]) {
block();
} else {
dispatch_sync(dispatch_get_main_queue(), block);
} 主執行緒非同步佇列 #define dispatch_main_async_safe(block)
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}

相關文章