---
title: "downloadTask(with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsession/downloadtask(with:)-1onj"
---

# downloadTask(with:)

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

## Declaration

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

## Parameters

- `url`: The URL to download.

## Mentioned in

Downloading files in the background Downloading files from websites

## Return Value

Return Value The new session download task.

## Discussion

Discussion After you create the task, you must start it by calling its resume() method.

## See Also

### Adding download tasks to a session

- [downloadTask(with:completionHandler:)](foundation/urlsession/downloadtask(with:completionhandler:)-7cuje.md)
- [downloadTask(with:)](foundation/urlsession/downloadtask(with:)-3fb7s.md)
- [downloadTask(with:completionHandler:)](foundation/urlsession/downloadtask(with:completionhandler:)-4a84s.md)
- [downloadTask(withResumeData:)](foundation/urlsession/downloadtask(withresumedata:).md)
- [downloadTask(withResumeData:completionHandler:)](foundation/urlsession/downloadtask(withresumedata:completionhandler:).md)
- [URLSessionDownloadTask](foundation/urlsessiondownloadtask.md)
- [URLSessionDownloadDelegate](foundation/urlsessiondownloaddelegate.md)
