---
title: OperationQueue
framework: foundation
role: symbol
role_heading: Class
path: foundation/operationqueue
---

# OperationQueue

A queue that regulates the execution of operations.

## Declaration

```swift
class OperationQueue
```

## Overview

Overview An operation queue invokes its queued Operation objects based on their priority and readiness. After you add an operation to a queue, it remains in the queue until the operation finishes its task. You can’t directly remove an operation from a queue after you add it. note: Operation queues retain operations until the operations finish, and queues themselves are retained until all operations are finished. Suspending an operation queue with operations that aren’t finished can result in a memory leak. For more information about using operation queues, see the Concurrency Programming Guide. Determine the Execution Order An operation queue organizes and invokes its operations according to their readiness, priority level, and interoperation dependencies. If all of the queued operations have the same queuePriority and the isReady property returns true, the queue invokes them in the order you added them. Otherwise, the operation queue always invokes the operation with the highest priority relative to the other ready operations. However, don’t rely on queue semantics to ensure a specific execution order of operations  because changes in the readiness of an operation can change the resulting execution order. Interoperation dependencies provide an absolute execution order for operations, even if those operations are located in different operation queues. An operation object isn’t ready to run until all of its dependent operations have finished running. For details on how to set priority levels and dependencies, see Managing Dependencies in Operation. Respond to Operation Cancelation Finishing its task doesn’t necessarily mean that the operation performed that task to completion; an operation can also be canceled. Canceling an operation object leaves the object in the queue but notifies the object that it should stop its task as quickly as possible. For currently executing operations, this means that the operation object’s work code must check the cancellation state, stop what it is doing, and mark itself as finished. For operations that are queued but not yet executing, the queue must still call the operation object’s start() method so that it can processes the cancellation event and mark itself as finished. note: Canceling an operation causes the operation to ignore any dependencies it may have. This behavior makes it possible for the queue to invoke the operation’s start() method as soon as possible. The start() method, in turn, moves the operation to the finished state so that it can be removed from the queue. For more information about operation cancellation, see Responding to the Cancel Command in Operation. Observe Operations Using Key-Value Observing The OperationQueue class is key-value coding (KVC) and key-value observing (KVO) compliant. You can observe these properties to control other parts of your application. To observe the properties, use the following key paths: operations — Read-only operationCount — Read-only maxConcurrentOperationCount — Readable and writable isSuspended — Readable and writable name — Readable and writable Although you can attach observers to these properties, don’t use Cocoa bindings to bind these properties to elements of your application’s user interface. Code associated with your user interface typically must run only in your app’s main thread. However, KVO notifications associated with an operation queue may occur in any thread. For more information about KVO and how to attach observers to an object, see the Key-Value Observing Programming Guide. Plan for Thread Safety You can safely use a single OperationQueue object from multiple threads without creating additional locks to synchronize access to that object. Operation queues use the Dispatch framework to initiate the execution of their operations. As a result, queues always invoke operations on a separate thread, regardless of whether the operation is synchronous or asynchronous.

## Topics

### Accessing Specific Operation Queues

- [main](foundation/operationqueue/main.md)
- [current](foundation/operationqueue/current.md)

### Managing Operations in the Queue

- [addOperation(_:)](foundation/operationqueue/addoperation(_:)-64o8a.md)
- [addOperations(_:waitUntilFinished:)](foundation/operationqueue/addoperations(_:waituntilfinished:).md)
- [addOperation(_:)](foundation/operationqueue/addoperation(_:)-5s294.md)
- [addBarrierBlock(_:)](foundation/operationqueue/addbarrierblock(_:).md)
- [cancelAllOperations()](foundation/operationqueue/cancelalloperations().md)
- [waitUntilAllOperationsAreFinished()](foundation/operationqueue/waituntilalloperationsarefinished().md)
- [operations](foundation/operationqueue/operations.md)
- [operationCount](foundation/operationqueue/operationcount.md)

### Managing the Execution of Operations

- [qualityOfService](foundation/operationqueue/qualityofservice.md)
- [maxConcurrentOperationCount](foundation/operationqueue/maxconcurrentoperationcount.md)
- [defaultMaxConcurrentOperationCount](foundation/operationqueue/defaultmaxconcurrentoperationcount.md)

### Monitoring Progress of Operations

- [progress](foundation/operationqueue/progress.md)

### Suspending Execution

- [isSuspended](foundation/operationqueue/issuspended.md)

### Configuring the Queue

- [name](foundation/operationqueue/name.md)
- [underlyingQueue](foundation/operationqueue/underlyingqueue.md)

### Scheduling Operations

- [schedule(after:tolerance:options:_:)](foundation/operationqueue/schedule(after:tolerance:options:_:).md)
- [schedule(after:interval:tolerance:options:_:)](foundation/operationqueue/schedule(after:interval:tolerance:options:_:).md)
- [schedule(options:_:)](foundation/operationqueue/schedule(options:_:).md)
- [now](foundation/operationqueue/now.md)
- [minimumTolerance](foundation/operationqueue/minimumtolerance.md)
- [OperationQueue.SchedulerTimeType](foundation/operationqueue/schedulertimetype.md)
- [OperationQueue.SchedulerOptions](foundation/operationqueue/scheduleroptions.md)

### Default Implementations

- [Scheduler Implementations](foundation/operationqueue/scheduler-implementations.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [ProgressReporting](foundation/progressreporting.md)
- [Scheduler](combine/scheduler.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Operations

- [Operation](foundation/operation.md)
- [BlockOperation](foundation/blockoperation.md)
