var httpCookie:NSHTTPCookieStorage=NSHTTPCookieStorage.sharedHTTPCookieStorage();
println(httpCookie)
<NSHTTPCookieStorage cookies count:2>
How can I loop it each a cookie?
var httpCookie:NSHTTPCookieStorage=NSHTTPCookieStorage.sharedHTTPCookieStorage();
println(httpCookie)
<NSHTTPCookieStorage cookies count:2>
How can I loop it each a cookie?
look at this code
var cookies:[NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as [NSHTTPCookie]
for cookie:NSHTTPCookie in cookies as [NSHTTPCookie] {
if cookie.name as String == "CookieName" {
var cookieValue : String = "CookieName=" + cookie.value! as String
//if you want to add to your request
youRequest.setValue(cookieValue, forHTTPHeaderField: "cookie")
}
}
With
URLSession
in Swift 5 a concise way to loop through the returned Cookies...Remember, cookies may already be inside the store. If you want a solid count, make sure - before you send the request - to clean up the Cookie store...