If you’re looking for one specific header value, it’s much easier to cast the value rather than the entire dictionary. For example:
import Foundation
let response = HTTPURLResponse(url: URL(string: "")!, statusCode: 200, httpVersion: nil, headerFields: ["Some-Header": "some-value"])!
print(response.allHeaderFields["Some-Header"] as? String)
// -> Optional("some-value")
print(response.allHeaderFields["Some-Other-Header"] as? String)
// -> nil`
In your case, however, you’d like to pass
allHeaderFields
through to
HTTPCookie.cookies(withResponseHeaderFields:for:)
. The fact that this doesn’t work out of the box is a bug IMO (r. 27,805,863).
HTTPURLResponse.allHeaderFields
should be a
[String:String]
in order to match this API and others (most notably,
URLRequest.allHTTPHeaderFields
).
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"