Instance Method


Returns all the cookie storage’s cookies that are sent to a specified URL.


func cookies(for URL: URL) -> [HTTPCookie]?



The URL to filter on.

Return Value

An array of cookies whose URL matches the provided URL.


You can use the requestHeaderFields(with:) method of HTTPCookie to turn the array returned by this method into a set of header fields to add to a URLRequest object.

If you override this method, also override getCookiesFor(_:completionHandler:).

See Also

Retrieving Cookies

var cookies: [HTTPCookie]?

The cookie storage’s cookies.

func getCookiesFor(URLSessionTask, completionHandler: ([HTTPCookie]?) -> Void)

Fetches cookies relevant to the specified task and passes them to the completion handler.

func sortedCookies(using: [NSSortDescriptor]) -> [HTTPCookie]

Returns all of the cookie storage’s cookies, sorted according to a given set of sort descriptors.