SDWebImage中两个比较好用的宏定义定义 之dispatch_main_async_safe

//主线程同步队列
#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);\
    }
//用法
  dispatch_main_async_safe(^{
                    //需要执行的代码片段;
                });

你可能感兴趣的:(IOS开发)