---
title: "setCookie(_:completionHandler:)"
framework: webkit
role: symbol
role_heading: Instance Method
path: "webkit/wkhttpcookiestore/setcookie(_:completionhandler:)"
---

# setCookie(_:completionHandler:)

Adds a cookie to the cookie store.

## Declaration

```swift
func setCookie(_ cookie: HTTPCookie, completionHandler: (@MainActor @Sendable () -> Void)? = nil)
```

```swift
func setCookie(_ cookie: HTTPCookie) async
```

## Parameters

- `cookie`: The cookie to add.
- `completionHandler`: A completion handler block to execute asynchronously after the method successfully stores the cookie. This block has no return value and no parameters.

## See Also

### Managing cookies

- [getAllCookies(_:)](webkit/wkhttpcookiestore/getallcookies(_:).md)
- [delete(_:completionHandler:)](webkit/wkhttpcookiestore/delete(_:completionhandler:).md)
