Tutorial by Examples

Grand Central Dispatch works on the concept of "Dispatch Queues". A dispatch queue executes tasks you designate in the order which they are passed. There are three types of dispatch queues: Serial Dispatch Queues (aka private dispatch queues) execute one task at a time, in order. They a...
3.0 To run tasks on a dispatch queue, use the sync, async, and after methods. To dispatch a task to a queue asynchronously: let queue = DispatchQueue(label: "myQueueName") queue.async { //do something DispatchQueue.main.async { //this will be called in main t...
GCD provides mechanism for performing a loop, whereby the loops happen concurrently with respect to each other. This is very useful when performing a series of computationally expensive calculations. Consider this loop: for index in 0 ..< iterations { // Do something computationally expens...
You can think of an OperationQueue as a line of tasks waiting to be executed. Unlike dispatch queues in GCD, operation queues are not FIFO (first-in-first-out). Instead, they execute tasks as soon as they are ready to be executed, as long as there are enough system resources to allow for it. Get th...
The Foundation framework provides the Operation type, which represents a high-level object that encapsulates a portion of work that may be executed on a queue. Not only does the queue coordinate the performance of those operations, but you can also establish dependencies between operations, create c...

Page 1 of 1