---
title: HTTPCookieStorage
framework: foundation
role: symbol
role_heading: Class
path: foundation/httpcookiestorage
---

# HTTPCookieStorage

A container that manages the storage of cookies.

## Declaration

```swift
class HTTPCookieStorage
```

## Overview

Overview Each stored cookie is represented by an instance of the HTTPCookie class. Sharing cookie storage The persistent cookie storage returned by shared may be available to app extensions or other apps, subject to the following guidelines: iOS — Each app and app extension has a unique data container, meaning  they have separate cookie stores. You can obtain a common cookie storage by using the sharedCookieStorage(forGroupContainerIdentifier:) method. macOS (non-sandboxed) — As of macOS 10.11, each app has its own cookie storage. Prior to macOS 10.11, a common cookie store is shared among the user’s apps. macOS (sandboxed) — Same as iOS. UIWebView — UIWebView instances within an app inherit the parent app’s shared cookie storage. WKWebView — Each WKWebView instance has its own cookie storage. See the WKHTTPCookieStore class for more information. Session cookies (where the cookie object’s isSessionOnly property is true) are local to a single process and are not shared. note: In cases where a cookie storage is shared between processes, changes made to the cookie accept policy affect all currently running apps using the cookie storage. Subclassing notes The HTTPCookieStorage class is usable as-is, but you can subclass it. For example, you can override the storage methods like storeCookies(_:for:), getCookiesFor(_:completionHandler:) to screen which cookies are stored, or reimplement the storage mechanism for security or other reasons. When overriding methods of this class, be aware that methods that take a task parameter are preferred by the system to equivalent methods that do not. Therefore, you should override the task-based methods when subclassing, as follows: Retrieving cookies — Override getCookiesFor(_:completionHandler:), instead of or in addition to cookies(for:). Adding cookies — Override storeCookies(_:for:), instead of or in addition to setCookies(_:for:mainDocumentURL:).

## Topics

### Getting the shared cookie storage object

- [shared](foundation/httpcookiestorage/shared.md)
- [sharedCookieStorage(forGroupContainerIdentifier:)](foundation/httpcookiestorage/sharedcookiestorage(forgroupcontaineridentifier:).md)

### Getting and setting the cookie accept policy

- [cookieAcceptPolicy](foundation/httpcookiestorage/cookieacceptpolicy.md)
- [HTTPCookie.AcceptPolicy](foundation/httpcookie/acceptpolicy.md)

### Adding and removing cookies

- [removeCookies(since:)](foundation/httpcookiestorage/removecookies(since:).md)
- [deleteCookie(_:)](foundation/httpcookiestorage/deletecookie(_:).md)
- [setCookie(_:)](foundation/httpcookiestorage/setcookie(_:).md)
- [setCookies(_:for:mainDocumentURL:)](foundation/httpcookiestorage/setcookies(_:for:maindocumenturl:).md)
- [storeCookies(_:for:)](foundation/httpcookiestorage/storecookies(_:for:).md)

### Retrieving cookies

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

### Tracking cookie storage changes

- [NSHTTPCookieManagerCookiesChanged](foundation/nsnotification/name-swift.struct/nshttpcookiemanagercookieschanged.md)
- [HTTPCookieStorage.CookiesChangedMessage](foundation/httpcookiestorage/cookieschangedmessage.md)
- [NSHTTPCookieManagerAcceptPolicyChanged](foundation/nsnotification/name-swift.struct/nshttpcookiemanageracceptpolicychanged.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Cookies

- [HTTPCookie](foundation/httpcookie.md)
