Skip to content

Instantly share code, notes, and snippets.

@tmdvs
Created October 17, 2012 09:38
Show Gist options
  • Save tmdvs/3904690 to your computer and use it in GitHub Desktop.
Save tmdvs/3904690 to your computer and use it in GitHub Desktop.
int64_t delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
<#code to be executed on the main queue after delay#>
});
// Do something in the background and then when done call something on the main thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
// My Background blocking code, vars defined above this dispatch or class vars can be accessed here
...
// Back to the main thread!
dispatch_async(dispatch_get_main_queue(), ^{
// update UI and what not, vars defined in the dispatch above or class vars can be accessed here, awesome scoping
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment