Kodeco Forums

Grand Central Dispatch In-Depth: Part 1/2

Concurrency is a tough topic. Learn about Grand Central Dispatch in-depth in this two part tutorial series.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2457-grand-central-dispatch-in-depth-part-1-2

In this part of the code
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ // 1
UIImage *overlayImage = [self faceOverlayImageFromImage:_image]; // Download
dispatch_async(dispatch_get_main_queue(), ^{ // 2
[self fadeInNewImage:overlayImage]; // 3
});
});

The queue DISPATCH_QUEUE_PRIORITY_HIGH is concurrent queue, so why does the // Download line waits till download is done to update the UI? the dispatch_async // 2 may start right after // Download line isn’t it?

dispatch_async(queue, block1);
dispatch_async(queue, block2);
dispatch_async(queue, block3);

block1, block2 and block3 are executed concurrently.
Lines in that blocks (such as // Download and // 2) are executed serially. There is no concurrency inside blocks.

To compile starter project you should add few lines in GooglyPuff-info.plist:

  1. App Transport Security Settings → Allow Arbitrary Loads: YES
  2. Privacy - Photo Library Usage Description: “some text to request access to photo library”

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]