ylliX - Online Advertising Network

Quick tip: Using background operations with Grand Central Dispatch

Yes, Grad Centeral Dispatch may seems big and complex. But if you need to put some work into background, its pretty easy, all you have to do is:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  // do your job here
});

Simple, isn’t it? In case you want to put more CPU cycles into your background process, you can change priority to DISPATCH_QUEUE_PRIORITY_DEFAULT or even DISPATCH_QUEUE_PRIORITY_HIGH. You can use also DISPATCH_QUEUE_PRIORITY_BACKGROUND but this one will cause your code to run at very end, when all higher priorities are done.

Leave a Reply