Created
July 29, 2014 23:21
-
-
Save jazzychad/850a4d9fed017d2a7fa6 to your computer and use it in GitHub Desktop.
mainqueue.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in some .h file | |
extern void runOnMainQueue(dispatch_block_t block); | |
extern void asyncRunOnMainQueue(dispatch_block_t block); | |
// in some .m file | |
void runOnMainQueue(dispatch_block_t block) | |
{ | |
if (block) { | |
if ([NSThread isMainThread]) { | |
block(); | |
} else { | |
dispatch_sync(dispatch_get_main_queue(), block); | |
} | |
} | |
} | |
void asyncRunOnMainQueue(dispatch_block_t block) | |
{ | |
if (block) { | |
dispatch_async(dispatch_get_main_queue(), block); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment