Execute code concurrently on multicore hardware by submitting work to dispatch queues managed by the system.


Dispatch, also known as Grand Central Dispatch (GCD), contains language features, runtime libraries, and system enhancements that provide systemic, comprehensive improvements to the support for concurrent code execution on multicore hardware in macOS, iOS, watchOS, and tvOS.

The BSD subsystem, Core Foundation, and Cocoa APIs have all been extended to use these enhancements to help both the system and your application to run faster, more efficiently, and with improved responsiveness. Consider how difficult it is for a single application to use multiple cores effectively, let alone to do it on different computers with different numbers of computing cores or in an environment with multiple applications competing for those cores. GCD, operating at the system level, can better accommodate the needs of all running applications, matching them to the available system resources in a balanced fashion.


Queues and Tasks

class DispatchQueue

An object that manages the execution of tasks serially or concurrently on your app's main thread or on a background thread.

class DispatchWorkItem

The work you want to perform, encapsulated in a way that lets you attach a completion handle or execution dependencies.

class DispatchGroup

A group of tasks that you monitor as a single unit.

Quality of Service

struct DispatchQoS

The quality of service, or the execution priority, to apply to tasks.

System Event Monitoring

class DispatchSource

An object that coordinates the processing of specific low-level system events, such as file-system events, timers, and UNIX signals.

class DispatchIO

An object that manages operations on a file descriptor using either stream-based or random-access semantics.

struct DispatchData

An object that manages a memory-based data buffer and exposes it as a contiguous block of memory.

struct DispatchDataIterator

A byte-by-byte iterator over the contents of a dispatch data object.

Task Synchronization

class DispatchSemaphore

An object that controls access to a resource across multiple execution contexts through use of a traditional counting semaphore.

Time Constructs

struct DispatchTime

A point in time relative to the default clock, with nanosecond precision.

struct DispatchWallTime

An absolute point in time according to the wall clock, with microsecond precision.

enum DispatchTimeInterval

A number of seconds, millisconds, microseconds, or nanoseconds.

enum DispatchTimeoutResult

A result value indicating whether a dispatch operation finished before a specified time.

typealias dispatch_time_t

An abstract representation of time.

Dispatch Objects

class DispatchObject

The base class for most dispatch types.

enum DispatchPredicate

Logical conditions to evaluate within a given execution context.

func dispatchPrecondition(condition: () -> DispatchPredicate)

Checks a dispatch condition necessary for further execution.