<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/HTTPCookie/cookies(withResponseHeaderFields:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSHTTPCookie(cm)cookiesWithResponseHeaderFields:forURL:"
  },
  "title" : "cookies(withResponseHeaderFields:for:)"
}
-->

# cookies(withResponseHeaderFields:for:)

Creates an array of HTTP cookies that corresponds to the provided response header fields for the provided URL.

```
class func cookies(withResponseHeaderFields headerFields: [String : String], for URL: URL) -> [HTTPCookie]
```

## Parameters

`headerFields`

The header fields used to create the [`HTTPCookie`](/documentation/Foundation/HTTPCookie) objects.

`URL`

The URL associated with the created cookies.

## Return Value

The array of created cookies.

## Discussion

This method ignores irrelevant header fields in `headerFields`, allowing dictionaries to contain additional data.

If `headerFields` doesn’t specify a domain for a given cookie, the cookie is created with a default domain value of `URL`.

If `headerFields` doesn’t specify a path for a given cookie, the cookie is created with a default path value of `"/"`.

---

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)