---
title: URLSessionTaskDelegate
framework: foundation
role: symbol
role_heading: Protocol
path: foundation/urlsessiontaskdelegate
---

# URLSessionTaskDelegate

A protocol that defines methods that URL session instances call on their delegates to handle task-level events.

## Declaration

```swift
protocol URLSessionTaskDelegate : URLSessionDelegate
```

## Mentioned in

Uploading streams of data Downloading files from websites Fetching website data into memory Uploading data to a website

## Overview

Overview You use this protocol in one of two ways, depending on how you use a URLSession: If you create tasks with Swift’s async-await syntax, using methods like bytes(for:delegate:) and data(for:delegate:), you pass a delegate argument of this type. The delegate receives callbacks for things like task progress, while the call point awaits the completion of the task. If you add tasks to the session with methods like dataTask(with:) and downloadTask(with:), then you implement this protocol’s methods in a delegate you set on the session. This session delegate may also implement other protocols as appropriate, like URLSessionDownloadDelegate and URLSessionDataDelegate. You can also assign a delegate of this type directly to the task to intercept callbacks before the task delivers them to the session’s delegate. note: Your URLSession object doesn’t need to have a delegate. If you don’t assign a delegate, the session uses a system-provided delegate. In this case, you must provide a completion callback or use the Swift async-await methods to obtain the data.

## Topics

### Handling task life cycle changes

- [urlSession(_:task:didCompleteWithError:)](foundation/urlsessiontaskdelegate/urlsession(_:task:didcompletewitherror:).md)

### Handling redirects

- [urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:)](foundation/urlsessiontaskdelegate/urlsession(_:task:willperformhttpredirection:newrequest:completionhandler:).md)

### Working with upload tasks

- [urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)](foundation/urlsessiontaskdelegate/urlsession(_:task:didsendbodydata:totalbytessent:totalbytesexpectedtosend:).md)
- [urlSession(_:task:needNewBodyStream:)](foundation/urlsessiontaskdelegate/urlsession(_:task:neednewbodystream:).md)

### Handling authentication challenges

- [urlSession(_:task:didReceive:completionHandler:)](foundation/urlsessiontaskdelegate/urlsession(_:task:didreceive:completionhandler:).md)
- [URLSession.AuthChallengeDisposition](foundation/urlsession/authchallengedisposition.md)

### Handling delayed and waiting tasks

- [urlSession(_:task:willBeginDelayedRequest:completionHandler:)](foundation/urlsessiontaskdelegate/urlsession(_:task:willbegindelayedrequest:completionhandler:).md)
- [URLSession.DelayedRequestDisposition](foundation/urlsession/delayedrequestdisposition.md)
- [urlSession(_:taskIsWaitingForConnectivity:)](foundation/urlsessiontaskdelegate/urlsession(_:taskiswaitingforconnectivity:).md)

### Collecting task metrics

- [urlSession(_:task:didFinishCollecting:)](foundation/urlsessiontaskdelegate/urlsession(_:task:didfinishcollecting:).md)
- [URLSessionTaskMetrics](foundation/urlsessiontaskmetrics.md)

### Instance Methods

- [urlSession(_:didCreateTask:)](foundation/urlsessiontaskdelegate/urlsession(_:didcreatetask:).md)
- [urlSession(_:task:didReceiveInformationalResponse:)](foundation/urlsessiontaskdelegate/urlsession(_:task:didreceiveinformationalresponse:).md)
- [urlSession(_:task:needNewBodyStreamFrom:completionHandler:)](foundation/urlsessiontaskdelegate/urlsession(_:task:neednewbodystreamfrom:completionhandler:).md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [URLSessionDelegate](foundation/urlsessiondelegate.md)

### Inherited By

- [URLSessionDataDelegate](foundation/urlsessiondatadelegate.md)
- [URLSessionDownloadDelegate](foundation/urlsessiondownloaddelegate.md)
- [URLSessionStreamDelegate](foundation/urlsessionstreamdelegate.md)
- [URLSessionWebSocketDelegate](foundation/urlsessionwebsocketdelegate.md)

## See Also

### Working with a delegate

- [delegate](foundation/urlsession/delegate.md)
- [URLSessionDelegate](foundation/urlsessiondelegate.md)
- [delegateQueue](foundation/urlsession/delegatequeue.md)
