In my iOS app I'm running a computationally intensive task on a background thread like this:
// f is called on the main thread
- (void) f {
[self performSelectorInBackground:@selector(doCalcs) withObject:nil];
}
- (void) doCalcs {
int r = expensiveFunction();
[self performSelectorOnMainThread:@selector(displayResults:) withObject:@(r) waitUntilDone:NO];
}
How can I use GCD to run an expensive calculation such that it doesn't block the main thread?
I've looked at dispatch_async
and some options for the GCD queue choice but I'm too new to GCD to feel like I understand it sufficiently.
dispatch_async
? – Wain