---
title: "performBackgroundTask(_:)"
framework: coredata
role: symbol
role_heading: Instance Method
path: "coredata/nspersistentcontainer/performbackgroundtask(_:)-39sch"
---

# performBackgroundTask(_:)

Executes a closure on a private queue using an ephemeral managed object context.

## Declaration

```swift
func performBackgroundTask(_ block: @escaping @Sendable (NSManagedObjectContext) -> Void)
```

## Parameters

- `block`: A closure that is executed by the persistent container against a newly created private context. The private context is passed into the block as part of the execution of the block.

## Mentioned in

Using Core Data in the background

## Discussion

Discussion Each time this method is invoked, the persistent container creates a new NSManagedObjectContext with the concurrencyType set to NSManagedObjectContextConcurrencyType.privateQueueConcurrencyType. The persistent container then executes the passed in block against that newly created context on the context’s private queue.

## See Also

### Performing Background Tasks

- [performBackgroundTask(_:)](coredata/nspersistentcontainer/performbackgroundtask(_:)-25nok.md)
