Is there a way to manually set cookies in Swift that don't expire at the end of a session? The docs say that sessionOnly
should default to false and can be set using the discard
property, but it doesn't seem to work for me. I've tried:
import Foundation
let cookie = HTTPCookie(properties: [
.domain: ".google.com",
.path: "/",
.name: "foo",
.value: "bar",
.discard: "FALSE"
])!
HTTPCookieStorage.shared.setCookie(cookie)
let cookies = HTTPCookieStorage.shared.cookies(for: URL(string: "https://google.com")!)
print(cookies)
// Optional([<NSHTTPCookie version:0 name:"foo" value:"bar" expiresDate:(null) created:2016-11-23 16:00:37 +0000 sessionOnly:TRUE domain:".google.com" partition:"none" path:"/" isSecure:FALSE>])
but as shown, the resulting cookie has a sessionOnly
value of true.