<!--
{
  "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/init(properties:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSHTTPCookie(im)initWithProperties:"
  },
  "title" : "init(properties:)"
}
-->

# init(properties:)

Initializes an HTTP cookie object with the given cookie properties.

```
init?(properties: [HTTPCookiePropertyKey : Any])
```

## Parameters

`properties`

The properties for the new cookie object, expressed as key-value pairs.

## Return Value

A new cookie object, with the given properies.

## Discussion

This initializer returns `nil` if the provided properties are invalid. To successfully create a cookie, you must provide values for (at least) the [`path`](/documentation/Foundation/HTTPCookiePropertyKey/path), [`name`](/documentation/Foundation/HTTPCookiePropertyKey/name), and [`value`](/documentation/Foundation/HTTPCookiePropertyKey/value) keys, and either the [`originURL`](/documentation/Foundation/HTTPCookiePropertyKey/originURL) key or the [`domain`](/documentation/Foundation/HTTPCookiePropertyKey/domain) key.

See Accepting cookies for more information on the available cookie attribute constants and the constraints imposed on the values in the dictionary.

## See Also

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

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



---

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)