Skip to content

Instantly share code, notes, and snippets.

@drance
Created May 28, 2014 00:22
Show Gist options
  • Save drance/d26278546acfaed54ba1 to your computer and use it in GitHub Desktop.
Save drance/d26278546acfaed54ba1 to your computer and use it in GitHub Desktop.
Run on the main thread. If we're already there, run synchronously.
@implementation NSOperationQueue (BHSAdditions)
+ (void)bhs_runOnMainQueue:(void (^)(void))block {
NSParameterAssert(block);
if ([NSThread isMainThread]) {
block();
} else {
[[self mainQueue] addOperationWithBlock:block];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment