<!--
{
  "availability" : [
    "iOS: 16.1.0 -",
    "iPadOS: 16.1.0 -",
    "macCatalyst: 16.1.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 18.4.0 -",
    "visionOS: 2.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "BackgroundAssets",
  "identifier" : "/documentation/BackgroundAssets/BADownloadManager/withExclusiveControl(before:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Background Assets",
      "BackgroundAssets"
    ],
    "preciseIdentifier" : "s:So17BADownloadManagerC16BackgroundAssetsE20withExclusiveControl6before_x10Foundation4DateV_xyKYTctYaKlF"
  },
  "title" : "withExclusiveControl(before:_:)"
}
-->

# withExclusiveControl(before:_:)

Attempts to acquire immediate, exclusive control over the download manager before the specified date.

```
@backDeployed(before: iOS 27, macOS 27, tvOS 27, visionOS 27)
final func withExclusiveControl<ReturnType>(before date: Date, _ body: @escaping () throws -> sending ReturnType) async throws -> sending ReturnType
```

## Parameters

`date`

The date before which to acquire exclusive control over the download manager.

`body`

A closure to execute with exclusive control over the download manager. Once the closure returns or throws, you lose exclusive control.

## Return Value

`body`’s return value.

## Discussion

To avoid races between your main app and your downloader extension, perform operations on the download manager—*e.g.*, fetching current downloads, scheduling new downloads, *etc.*—while maintaining exclusive control over it. Use this method instead of [`withExclusiveControl(_:)`](/documentation/BackgroundAssets/BADownloadManager/withExclusiveControl(_:)-1rf9w) to enforce that the attempt to acquire exclusive control fail if the system can’t fulfill it before a particular date. Unlike [`withExclusiveControl(beforeDate:perform:)`](/documentation/BackgroundAssets/BADownloadManager/withExclusiveControl(beforeDate:perform:)), this method waits for exclusive control to be acquired and then relinquished before it returns.

> Throws: When `body` throws or when exclusive control over the download manager can’t be acquired before `date`.

---

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)