Skip to content

Instantly share code, notes, and snippets.

@Sunnyztj
Created October 29, 2014 04:08
Show Gist options
  • Save Sunnyztj/e4338327094ef7ae094b to your computer and use it in GitHub Desktop.
Save Sunnyztj/e4338327094ef7ae094b to your computer and use it in GitHub Desktop.
dispatch_async
The main reason you use the default queue over the main queue is to run tasks in the background.
For instance, if I am downloading a file from the internet and I want to update the user on the progress of the download, I will run the download in the priority default queue and update the UI in the main queue asynchronously.
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
dispatch_async(dispatch_get_main_queue(), ^(void){
//Run UI Updates
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment