---
title: "getCookiesFor(_:completionHandler:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/httpcookiestorage/getcookiesfor(_:completionhandler:)"
---

# getCookiesFor(_:completionHandler:)

Fetches cookies relevant to the specified task and passes them to the completion handler.

## Declaration

```swift
func getCookiesFor(_ task: URLSessionTask, completionHandler: @escaping @Sendable ([HTTPCookie]?) -> Void)
```

```swift
func cookies(for task: URLSessionTask) async -> [HTTPCookie]?
```

## Parameters

- `task`: The task performing a request. The cookie storage can use the URL and other properties of this task’s request to determine which cookies to fetch.
- `completionHandler`: A completion handler that receives an array of cookies as its argument.

## See Also

### Retrieving cookies

- [cookies](foundation/httpcookiestorage/cookies.md)
- [cookies(for:)](foundation/httpcookiestorage/cookies(for:).md)
- [sortedCookies(using:)](foundation/httpcookiestorage/sortedcookies(using:).md)
