Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
simple function for running UI Updates (or anything) on main thread for Cocoa. Can be useful if you have a callback you are not sure it always runs on main thread.
void onMainQueue(void(^block)(void)) {
if ([NSThread isMainThread])
dispatch_sync(dispatch_get_main_queue(), block);
//usage example:
- (void)callbackThatIDontKnowWhichThreadIsItRunningOn {
[UIView beginAnimations:nil context:nil];
self.alpha = 0;
[UIView commitAnimations];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.