Last active
December 17, 2015 04:48
-
-
Save furkanmustafa/5552878 to your computer and use it in GitHub Desktop.
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.
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
void onMainQueue(void(^block)(void)) { | |
if ([NSThread isMainThread]) | |
block(); | |
else | |
dispatch_sync(dispatch_get_main_queue(), block); | |
} | |
//usage example: | |
- (void)callbackThatIDontKnowWhichThreadIsItRunningOn { | |
onMainQueue(^{ | |
[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