Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Baekalfen/11296773 to your computer and use it in GitHub Desktop.
Save Baekalfen/11296773 to your computer and use it in GitHub Desktop.
Running a method async, and call method on finish in Objective-C. Good for running method while updating the UI on OS X. Used some code from here: http://stackoverflow.com/questions/8854100/objective-c-async-call-a-method-using-ios-4
- (void) someMethod{
[self dispatchBlockAsync:^{
[self method1];
} callOnReturn:^{
[self method2];]
}];
}
- (void)dispatchBlockAsync:(void(^)(void))callBlock callOnReturn:(void(^)(void))returnBlock{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^ {
callBlock();
dispatch_async(dispatch_get_main_queue(), ^ {
returnBlock();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment