---
title: "init(task:cachedResponse:client:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/urlprotocol/init(task:cachedresponse:client:)"
---

# init(task:cachedResponse:client:)

Creates a URL protocol instance to handle the task.

## Declaration

```swift
convenience init(task: URLSessionTask, cachedResponse: CachedURLResponse?, client: (any URLProtocolClient)?)
```

## Parameters

- `task`: A task containing a URL request to be performed by the protocol.
- `cachedResponse`: A cached response for the task; may be nil if there is no existing cached response for the task.
- `client`: An object that provides an implementation of the doc://com.apple.foundation/documentation/Foundation/URLProtocolClient protocol that this instance uses to communicate with the URL loading system. This client object is retained.

## Return Value

Return Value The initialized protocol object.

## Discussion

Discussion Subclasses should override this method to do any custom initialization. Don’t call this method explicitly. When you register your custom protocol class, the system will initialize instances of your protocol as needed. This initializer calls through to init(request:cachedResponse:client:).

## See Also

### Creating protocol objects

- [init(request:cachedResponse:client:)](foundation/urlprotocol/init(request:cachedresponse:client:).md)
