<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Task/detached(name:executorPreference:priority:operation:)-6r16s",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:ScT12_Concurrencys5Error_pRs_rlE8detached4name18executorPreference8priority9operationScTyxsAB_pGSSSg_Sch_pSgScPSgxyYaKcntFZ"
  },
  "title" : "detached(name:executorPreference:priority:operation:)"
}
-->

# detached(name:executorPreference:priority:operation:)

Runs the given throwing operation asynchronously
as part of a new *unstructured* *detached* top-level task.

```
@discardableResult static func detached(name: String? = nil, executorPreference taskExecutor: (any TaskExecutor)?, priority: TaskPriority? = nil, operation: sending @escaping () async throws -> Success) -> Task<Success, any Error>
```

## Parameters

`name`

Human readable name of the task.

`taskExecutor`

The task executor that the child task should be started on and keep using.
Explicitly passing `nil` as the executor preference is equivalent to no preference,
and effectively means to inherit the outer context’s executor preference.
You can also pass the [`globalConcurrentExecutor`](/documentation/Swift/globalConcurrentExecutor) global executor explicitly.

`priority`

The priority of the operation task.
Omit this parameter or pass `nil` to inherit the enclosing context’s base priority.

`operation`

The operation to perform.

## Return Value

A reference to the task.

## Discussion

If the `operation` throws an error, it is caught by the `Task` and will be
rethrown only when the task’s `value` is awaited. Take care to not accidentally
dismiss errors by not awaiting on the task’s resulting value.

Don’t use a detached unstructured task if it’s possible
to model the operation using structured concurrency features like child tasks.
Child tasks inherit the parent task’s priority and task-local storage,
and canceling a parent task automatically cancels all of its child tasks.
You need to handle these considerations manually with a detached task.

You need to keep a reference to the task
if you want to cancel it by calling the `Task.cancel()` method.
Discarding your reference to a task
doesn’t implicitly cancel that task,
it only makes it impossible for you to explicitly cancel the task.

---

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)