Learn about cookies and their role in networking. You’ll also work with cookies.
This is a companion discussion topic for the original entry at https://www.kodeco.com/32317111-advanced-networking-with-urlsession/lessons/11
Learn about cookies and their role in networking. You’ll also work with cookies.
I think there’s an error with setting the cookie towards the end of the video here. According to the documentation, for HTTPCookie to be created we also need to pass in the path value, otherwise the initialiser returns nil.
var cookieProperties: [HTTPCookiePropertyKey: Any] = [:]
cookieProperties[.name] = cookie.name
cookieProperties[.value] = cookie.value
cookieProperties[.domain] = cookie.domain
cookieProperties[.path] = cookie.path // Should be included
if let myCookie = HTTPCookie(properties: cookieProperties) {
HTTPCookieStorage.shared.setCookie(myCookie)
HTTPCookieStorage.shared.deleteCookie(cookie)
print("MyCookie is valid!")
}
Thank you for catching that. Your are indeed correct, and it may be something that changed from the development of the course to the time the new Xcode version and API updates came about.
I’ll take note so we can add it as a note in the video itself for other students of the course.
Thanks once more for catching that and happy coding!