---
title: "cookies(for:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/httpcookiestorage/cookies(for:)"
---

# cookies(for:)

Returns all the cookie storage’s cookies that are sent to a specified URL.

## Declaration

```swift
func cookies(for URL: URL) -> [HTTPCookie]?
```

## Parameters

- `URL`: The URL to filter on.

## Return Value

Return Value An array of cookies whose URL matches the provided URL.

## Discussion

Discussion You can use the requestHeaderFields(with:) method of HTTPCookie to turn the array returned by this method into a set of header fields to add to a URLRequest object (or NSMutableURLRequest in Objective-C). If you override this method, also override getCookiesFor(_:completionHandler:).

## See Also

### Retrieving cookies

- [cookies](foundation/httpcookiestorage/cookies.md)
- [getCookiesFor(_:completionHandler:)](foundation/httpcookiestorage/getcookiesfor(_:completionhandler:).md)
- [sortedCookies(using:)](foundation/httpcookiestorage/sortedcookies(using:).md)
