<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchWorkItem",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "s:8Dispatch0A8WorkItemC"
  },
  "title" : "DispatchWorkItem"
}
-->

# DispatchWorkItem

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

```
class DispatchWorkItem
```

## Overview

A [`DispatchWorkItem`](/documentation/Dispatch/DispatchWorkItem) encapsulates work to be performed on a dispatch queue or within a dispatch group. You can also use a work item as a [`DispatchSource`](/documentation/Dispatch/DispatchSource) event, registration, or cancellation handler.

## Topics

### Creating a Work Item

[`init(qos:flags:block:)`](/documentation/Dispatch/DispatchWorkItem/init(qos:flags:block:))

Creates a new dispatch work item from an existing block and assigns it the specified quality-of-service class.

[`DispatchWorkItemFlags`](/documentation/Dispatch/DispatchWorkItemFlags)

A set of behaviors for a work item, such as its quality-of-service class and whether to create a barrier or spawn a new detached thread.

### Executing the Work Item

[`perform()`](/documentation/Dispatch/DispatchWorkItem/perform())

Executes the work item’s block synchronously on the current thread.

### Adding a Completion Handler

[`notify(queue:execute:)`](/documentation/Dispatch/DispatchWorkItem/notify(queue:execute:))

Schedules the execution of the specified work item after the completion of the current work item.

[`notify(qos:flags:queue:execute:)`](/documentation/Dispatch/DispatchWorkItem/notify(qos:flags:queue:execute:))

Schedules the execution of the specified work item, with the specified quality-of-service, after the completion of the current work item.

### Waiting for the Completion of a Work Item

[`wait()`](/documentation/Dispatch/DispatchWorkItem/wait())

Causes the caller to wait synchronously until the dispatch work item finishes executing.

[`wait(timeout:)`](/documentation/Dispatch/DispatchWorkItem/wait(timeout:))

Causes the caller to wait synchronously until the dispatch work item finishes executing, or until the specified time elapses.

[`wait(wallTimeout:)`](/documentation/Dispatch/DispatchWorkItem/wait(wallTimeout:))

Causes the caller to wait synchronously until the dispatch work item finishes executing, or until the specified time elapses.

[`DispatchTime`](/documentation/Dispatch/DispatchTime)

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

[`DispatchWallTime`](/documentation/Dispatch/DispatchWallTime)

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

### Canceling a Work Item

[`cancel()`](/documentation/Dispatch/DispatchWorkItem/cancel())

Cancels the current work item asynchronously.

[`isCancelled`](/documentation/Dispatch/DispatchWorkItem/isCancelled)

A Boolean value indicating whether the work item has been canceled.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)
