Instance Method

setTarget(queue:)

Sets the target queue for the given object.

Declaration

func setTarget(queue: DispatchQueue?)

Parameters

object

The object to modify. This parameter cannot be NULL.

queue

The new target queue for the object. The queue is retained, and the previous one, if any, is released. This parameter cannot be NULL.

Discussion

An object's target queue is responsible for processing the object. The target queue determines the queue on which the object's finalizer is invoked. In addition, modifying the target queue of some objects changes their behavior:

  • Dispatch queues:

    A dispatch queue's priority is inherited from its target queue. Use the dispatch_get_global_queue(_:_:) function to obtain a suitable target queue of the desired priority.

    If you submit a block to a serial queue, and the serial queue’s target queue is a different serial queue, that block is not invoked concurrently with blocks submitted to the target queue or to any other queue with that same target queue.

  • Dispatch sources:

    A dispatch source's target queue specifies where its event handler and cancellation handler blocks are submitted.

  • Dispatch I/O channels:

    A dispatch I/O channel's target queue specifies where its I/O operations are executed. This may affect the priority of the resulting I/O operations. For example, if the channel's target queue's priority is set to DISPATCH_QUEUE_PRIORITY_BACKGROUND, then any I/O operations performed by read(offset:length:queue:ioHandler:) or write(offset:data:queue:ioHandler:) on that queue are throttled when there is I/O contention.

See Also

Managing Dispatch Queues

class DispatchQueue

DispatchQueue manages the execution of work items. Each work item submitted to a queue is processed on a pool of threads managed by the system.

class DispatchSpecificKey

DispatchSpecificKey is a class that encapsulates keys that can be associated with a contextual value on a DispatchQueue using the setSpecific<T>(key:value:) method, and accessed using the getSpecific<T>(key:) method.

func dispatch_get_current_queue()

Returns the queue on which the currently executing block is running.

Deprecated
func dispatchMain()

Executes blocks submitted to the main queue.