<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSession/downloadTask(with:)-1onj",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLSession(im)downloadTaskWithURL:"
  },
  "title" : "downloadTask(with:)"
}
-->

# downloadTask(with:)

Creates a download task that retrieves the contents of the specified URL and saves the results to a file.

```
func downloadTask(with url: URL) -> URLSessionDownloadTask
```

## Parameters

`url`

The URL to download.

## Return Value

The new session download task.

## Discussion

After you create the task, you must start it by calling its [`resume()`](/documentation/Foundation/URLSessionTask/resume()) method.

---

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)