<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSHTTPCookie"
  },
  "title" : "HTTPCookie"
}
-->

# HTTPCookie

A representation of an HTTP cookie.

```
class HTTPCookie
```

## Overview

An [`HTTPCookie`](/documentation/Foundation/HTTPCookie) object is immutable, initialized from a dictionary that contains the attributes of the cookie. This class supports two different cookie versions:

- Version 0: The original cookie format defined by Netscape. Most cookies are in this format.
- Version 1: The cookie format defined in [RFC 6265](https://tools.ietf.org/html/rfc6265), HTTP State Management Mechanism.

## Topics

### Creating cookies

[`cookies(withResponseHeaderFields:for:)`](/documentation/Foundation/HTTPCookie/cookies(withResponseHeaderFields:for:))

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

[`cookieWithProperties:`](/documentation/Foundation/NSHTTPCookie/cookieWithProperties:)

Creates and initializes an HTTP cookie object using the provided properties.

[`init(properties:)`](/documentation/Foundation/HTTPCookie/init(properties:))

Initializes an HTTP cookie object with the given cookie properties.

### Converting cookies to request headers

[`requestHeaderFields(with:)`](/documentation/Foundation/HTTPCookie/requestHeaderFields(with:))

Converts an array of cookies to a dictionary of header fields.

### Getting cookie host properties

[`domain`](/documentation/Foundation/HTTPCookie/domain)

The domain of the cookie.

[`path`](/documentation/Foundation/HTTPCookie/path)

The cookie’s path.

[`portList`](/documentation/Foundation/HTTPCookie/portList)

The cookie’s port list.

### Getting cookie metadata

[`name`](/documentation/Foundation/HTTPCookie/name)

The cookie’s name.

[`value`](/documentation/Foundation/HTTPCookie/value)

The cookie’s string value.

[`version`](/documentation/Foundation/HTTPCookie/version)

The cookie’s version.

### Determining cookie lifespan

[`expiresDate`](/documentation/Foundation/HTTPCookie/expiresDate)

The cookie’s expiration date.

[`isSessionOnly`](/documentation/Foundation/HTTPCookie/isSessionOnly)

A Boolean value that indicates whether the cookie should be discarded at the end of the session (regardless of expiration date).

### Securing cookies

[`isHTTPOnly`](/documentation/Foundation/HTTPCookie/isHTTPOnly)

A Boolean value that indicates whether the cookie should only be sent to HTTP servers.

[`isSecure`](/documentation/Foundation/HTTPCookie/isSecure)

A Boolean value that indicates whether the cookie may only be sent over secure channels.

[`sameSitePolicy`](/documentation/Foundation/HTTPCookie/sameSitePolicy)

A Boolean value that indicates whether to restrict the cookie to requests sent back to the same site that created it.

[`HTTPCookieStringPolicy`](/documentation/Foundation/HTTPCookieStringPolicy)

Values that indicate whether to restrict the cookie to requests sent back to the same site that created it.

### Accessing cookie properties as key-value pairs

[`properties`](/documentation/Foundation/HTTPCookie/properties)

The cookie’s properties.

[`HTTPCookiePropertyKey`](/documentation/Foundation/HTTPCookiePropertyKey)

Constants that define the supported keys in a cookie attributes dictionary.

### Getting user-readable cookie metadata

[`comment`](/documentation/Foundation/HTTPCookie/comment)

The cookie’s comment string.

[`commentURL`](/documentation/Foundation/HTTPCookie/commentURL)

The cookie’s comment URL.

### Accepting cookies

[`HTTPCookie.AcceptPolicy`](/documentation/Foundation/HTTPCookie/AcceptPolicy)

Cookie acceptance policies implemented by the [`HTTPCookieStorage`](/documentation/Foundation/HTTPCookieStorage) class.



---

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)