-
-
Save rlb3/975112 to your computer and use it in GitHub Desktop.
Tricks with grand central dispatch
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
// Using grand central dispatch (GCD) so we don't block the GUI | |
dispatch_async(dispatch_get_global_queue(0, 0), ^{ | |
// Background, long stuff runs here, but doesn't affect the GUI | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
// The GUI thread stuff goes here | |
[self.tableView reloadData]; // example | |
}); | |
}); | |
// Just like javascript's setTimeout: call a block after a delay, on the main thread: | |
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 0.5); // Make it happen in half a second | |
dispatch_after(delay, dispatch_get_main_queue(), ^(void){ | |
// This will happen after the delay | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment