Created
October 17, 2012 09:38
-
-
Save tmdvs/3904690 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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