---
title: "urlSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsessiondownloaddelegate/urlsession(_:downloadtask:didwritedata:totalbyteswritten:totalbytesexpectedtowrite:)"
---

# urlSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)

Periodically informs the delegate about the download’s progress.

## Declaration

```swift
optional func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
```

## Parameters

- `session`: The session containing the download task.
- `downloadTask`: The download task.
- `bytesWritten`: The number of bytes transferred since the last time this delegate method was called.
- `totalBytesWritten`: The total number of bytes transferred so far.
- `totalBytesExpectedToWrite`: The expected length of the file, as provided by the Content-Length header. If this header was not provided, the value is doc://com.apple.foundation/documentation/Foundation/NSURLSessionTransferSizeUnknown.

## Mentioned in

Downloading files from websites
