Skip to content

Commit 93c455f

Browse files
author
Pushkar N Kulkarni
committed
Swift 3 API parity: Change type of HTTPURLResponse.allHeaderFields to match Darwin
1 parent ff652d6 commit 93c455f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

Foundation/NSURLResponse.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ open class HTTPURLResponse : URLResponse {
154154
///
155155
/// - Important: This is an *experimental* change from the
156156
/// `[NSObject: AnyObject]` type that Darwin Foundation uses.
157-
public let allHeaderFields: [String: String]
157+
public let allHeaderFields: [AnyHashable : Any]
158158

159159
/// Convenience method which returns a localized string
160160
/// corresponding to the status code for this response.
@@ -233,7 +233,8 @@ open class HTTPURLResponse : URLResponse {
233233
/// This property is intended to produce readable output.
234234
override open var description: String {
235235
var result = "<\(type(of: self)) \(Unmanaged.passUnretained(self).toOpaque())> { URL: \(url!.absoluteString) }{ status: \(statusCode), headers {\n"
236-
for(key, value) in allHeaderFields {
236+
for(aKey, aValue) in allHeaderFields {
237+
guard let key = aKey as? String, let value = aValue as? String else { continue } //shouldn't typically fail here
237238
if((key.lowercased() == "content-disposition" && suggestedFilename != "Unknown") || key.lowercased() == "content-type") {
238239
result += " \"\(key)\" = \"\(value)\";\n"
239240
} else {

TestFoundation/TestNSURLResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ class TestNSHTTPURLResponse : XCTestCase {
156156
let f = ["A": "1", "B": "2"]
157157
let sut = HTTPURLResponse(url: url, statusCode: 200, httpVersion: "HTTP/1.1", headerFields: f)
158158
XCTAssertEqual(sut?.allHeaderFields.count, 2)
159-
XCTAssertEqual(sut?.allHeaderFields["A"], "1")
160-
XCTAssertEqual(sut?.allHeaderFields["B"], "2")
159+
XCTAssertEqual(sut?.allHeaderFields["A"] as! String, "1")
160+
XCTAssertEqual(sut?.allHeaderFields["B"] as! String, "2")
161161
}
162162

163163
// Note that the message content length is different from the message

0 commit comments

Comments
 (0)