<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/HTTPCookieStorage/getCookiesFor(_:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSHTTPCookieStorage(im)getCookiesForTask:completionHandler:"
  },
  "title" : "getCookiesFor(_:completionHandler:)"
}
-->

# getCookiesFor(_:completionHandler:)

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

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

## 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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)