Delete all cookies in iOS NSURLSession

How can I delete all cookies from the NSHTTPCookieStorage.sharedHTTPCookieStorage file? The only methods I know about deleting one specified cookie, however, cookies are processed behind the scenes of NSURLSession. (Programming in Swift)

+5
source share
3 answers
let cookieStore = NSHTTPCookieStorage.sharedHTTPCookieStorage() for cookie in cookieStore.cookies ?? [] { cookieStore.deleteCookie(cookie) } 
+9
source

Similarly, for fast 3.0+, xCode 8.0 +

 let cookieStore = HTTPCookieStorage.shared for cookie in cookieStore.cookies ?? [] { cookieStore.deleteCookie(cookie) } 
+4
source

This gives the same result as the other answers, but with one line of code:

 HTTPCookieStorage.shared.cookies?.forEach(HTTPCookieStorage.shared.deleteCookie) 
+3
source

Source: https://habr.com/ru/post/1245166/


All Articles