Instance Method

cookies(for:)

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

Declaration

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

Parameters

theURL

The URL to filter on.

Return Value

An array of cookies whose URL matches the provided URL.

Discussion

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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software