Skip to content

Instantly share code, notes, and snippets.

@dreampiggy
Created April 13, 2017 07:22
Show Gist options
  • Save dreampiggy/92033875eb80471c70cefff8e43d227d to your computer and use it in GitHub Desktop.
Save dreampiggy/92033875eb80471c70cefff8e43d227d to your computer and use it in GitHub Desktop.
GCD main queue Macro
#ifndef dispatch_main_sync_safe
#define dispatch_main_sync_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}
#endif
#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment