Skip to content

Commit 5ab4679

Browse files
authored
Merge pull request #658 from e78l/no-nil-any-warn
2 parents 6c5b7db + 02a490e commit 5ab4679

File tree

6 files changed

+121
-84
lines changed

6 files changed

+121
-84
lines changed

Foundation/NSHTTPCookie.swift

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,42 @@ extension HTTPCookiePropertyKey {
3737

3838
/// Key for cookie value
3939
public static let value = HTTPCookiePropertyKey(rawValue: "Value")
40-
40+
4141
/// Key for cookie origin URL
4242
public static let originURL = HTTPCookiePropertyKey(rawValue: "OriginURL")
4343

4444
/// Key for cookie version
4545
public static let version = HTTPCookiePropertyKey(rawValue: "Version")
46-
46+
4747
/// Key for cookie domain
4848
public static let domain = HTTPCookiePropertyKey(rawValue: "Domain")
49-
49+
5050
/// Key for cookie path
5151
public static let path = HTTPCookiePropertyKey(rawValue: "Path")
52-
52+
5353
/// Key for cookie secure flag
5454
public static let secure = HTTPCookiePropertyKey(rawValue: "Secure")
55-
55+
5656
/// Key for cookie expiration date
5757
public static let expires = HTTPCookiePropertyKey(rawValue: "Expires")
5858

5959
/// Key for cookie comment text
6060
public static let comment = HTTPCookiePropertyKey(rawValue: "Comment")
61-
61+
6262
/// Key for cookie comment URL
6363
public static let commentURL = HTTPCookiePropertyKey(rawValue: "CommentURL")
64-
64+
6565
/// Key for cookie discard (session-only) flag
6666
public static let discard = HTTPCookiePropertyKey(rawValue: "Discard")
67-
67+
6868
/// Key for cookie maximum age (an alternate way of specifying the expiration)
6969
public static let maximumAge = HTTPCookiePropertyKey(rawValue: "Max-Age")
7070

7171
/// Key for cookie ports
7272
public static let port = HTTPCookiePropertyKey(rawValue: "Port")
73+
74+
// For Cocoa compatibility
75+
internal static let created = HTTPCookiePropertyKey(rawValue: "Created")
7376
}
7477

7578
/// `NSHTTPCookie` represents an http cookie.
@@ -94,10 +97,10 @@ open class HTTPCookie : NSObject {
9497
let _version: Int
9598
var _properties: [HTTPCookiePropertyKey : Any]
9699

97-
static let _attributes: [HTTPCookiePropertyKey] = [.name, .value, .originURL, .version,
98-
.domain, .path, .secure, .expires,
99-
.comment, .commentURL, .discard, .maximumAge,
100-
.port]
100+
static let _attributes: [HTTPCookiePropertyKey]
101+
= [.name, .value, .originURL, .version, .domain,
102+
.path, .secure, .expires, .comment, .commentURL,
103+
.discard, .maximumAge, .port]
101104

102105
/// Initialize a NSHTTPCookie object with a dictionary of parameters
103106
///
@@ -268,7 +271,7 @@ open class HTTPCookie : NSObject {
268271
version = 0
269272
}
270273
_version = version
271-
274+
272275
if let portString = properties[.port] as? String, _version == 1 {
273276
_portList = portString.characters
274277
.split(separator: ",")
@@ -300,8 +303,7 @@ open class HTTPCookie : NSObject {
300303
} else {
301304
_expiresDate = nil
302305
}
303-
304-
306+
305307
if let discardString = properties[.discard] as? String {
306308
_sessionOnly = discardString == "TRUE"
307309
} else {
@@ -321,23 +323,38 @@ open class HTTPCookie : NSObject {
321323
}
322324
}
323325
_HTTPOnly = false
324-
_properties = [.comment : properties[.comment],
325-
.commentURL : properties[.commentURL],
326-
HTTPCookiePropertyKey(rawValue: "Created") : Date().timeIntervalSinceReferenceDate, // Cocoa Compatibility
327-
.discard : _sessionOnly,
328-
.domain : _domain,
329-
.expires : _expiresDate,
330-
.maximumAge : properties[.maximumAge],
331-
.name : _name,
332-
.originURL : properties[.originURL],
333-
.path : _path,
334-
.port : _portList,
335-
.secure : _secure,
336-
.value : _value,
337-
.version : _version
326+
327+
328+
_properties = [
329+
.created : Date().timeIntervalSinceReferenceDate, // Cocoa Compatibility
330+
.discard : _sessionOnly,
331+
.domain : _domain,
332+
.name : _name,
333+
.path : _path,
334+
.secure : _secure,
335+
.value : _value,
336+
.version : _version
338337
]
338+
if let comment = properties[.comment] {
339+
_properties[.comment] = comment
340+
}
341+
if let commentURL = properties[.commentURL] {
342+
_properties[.commentURL] = commentURL
343+
}
344+
if let expires = properties[.expires] {
345+
_properties[.expires] = expires
346+
}
347+
if let maximumAge = properties[.maximumAge] {
348+
_properties[.maximumAge] = maximumAge
349+
}
350+
if let originURL = properties[.originURL] {
351+
_properties[.originURL] = originURL
352+
}
353+
if let _portList = _portList {
354+
_properties[.port] = _portList
355+
}
339356
}
340-
357+
341358
/// Return a dictionary of header fields that can be used to add the
342359
/// specified cookies to the request.
343360
///
@@ -355,7 +372,7 @@ open class HTTPCookie : NSObject {
355372
}
356373
return ["Cookie": cookieString]
357374
}
358-
375+
359376
/// Return an array of cookies parsed from the specified response header fields and URL.
360377
///
361378
/// This method will ignore irrelevant header fields so
@@ -371,7 +388,7 @@ open class HTTPCookie : NSObject {
371388
// names and values. This implementation takes care of multiple cookies in the same field, however it doesn't
372389
//support commas and semicolons in names and values(except for dates)
373390

374-
guard let cookies: String = headerFields["Set-Cookie"] else { return [] }
391+
guard let cookies: String = headerFields["Set-Cookie"] else { return [] }
375392

376393
let nameValuePairs = cookies.components(separatedBy: ";") //split the name/value and attribute/value pairs
377394
.map({$0.trim()}) //trim whitespaces
@@ -383,7 +400,7 @@ open class HTTPCookie : NSObject {
383400

384401
//mark cookie boundaries in the name-value array
385402
var cookieIndices = (0..<nameValuePairs.count).filter({nameValuePairs[$0].hasPrefix("Name")})
386-
cookieIndices.append(nameValuePairs.count)
403+
cookieIndices.append(nameValuePairs.count)
387404

388405
//bake the cookies
389406
var httpCookies: [HTTPCookie] = []
@@ -392,9 +409,9 @@ open class HTTPCookie : NSObject {
392409
httpCookies.append(aCookie)
393410
}
394411
}
395-
412+
396413
return httpCookies
397-
}
414+
}
398415

399416
//Bake a cookie
400417
private class func createHttpCookie(url: URL, pairs: ArraySlice<String>) -> HTTPCookie? {
@@ -403,20 +420,20 @@ open class HTTPCookie : NSObject {
403420
let name = pair.components(separatedBy: "=")[0]
404421
var value = pair.components(separatedBy: "\(name)=")[1] //a value can have an "="
405422
if canonicalize(name) == .expires {
406-
value = value.insertComma(at: 3) //re-insert the comma
423+
value = value.insertComma(at: 3) //re-insert the comma
407424
}
408425
properties[canonicalize(name)] = value
409426
}
410-
427+
411428
//if domain wasn't provided use the URL
412429
if properties[.domain] == nil {
413430
properties[.domain] = url.absoluteString
414431
}
415-
432+
416433
//the default Path is "/"
417434
if properties[.path] == nil {
418435
properties[.path] = "/"
419-
}
436+
}
420437

421438
return HTTPCookie(properties: properties)
422439
}
@@ -470,25 +487,25 @@ open class HTTPCookie : NSObject {
470487
open var properties: [HTTPCookiePropertyKey : Any]? {
471488
return _properties
472489
}
473-
490+
474491
/// The version of the receiver.
475492
///
476493
/// Version 0 maps to "old-style" Netscape cookies.
477494
/// Version 1 maps to RFC2965 cookies. There may be future versions.
478495
open var version: Int {
479496
return _version
480497
}
481-
498+
482499
/// The name of the receiver.
483500
open var name: String {
484501
return _name
485502
}
486-
503+
487504
/// The value of the receiver.
488505
open var value: String {
489506
return _value
490507
}
491-
508+
492509
/// Returns The expires date of the receiver.
493510
///
494511
/// The expires date is the date when the cookie should be
@@ -497,7 +514,7 @@ open class HTTPCookie : NSObject {
497514
/*@NSCopying*/ open var expiresDate: Date? {
498515
return _expiresDate
499516
}
500-
517+
501518
/// Whether the receiver is session-only.
502519
///
503520
/// `true` if this receiver should be discarded at the end of the
@@ -506,7 +523,7 @@ open class HTTPCookie : NSObject {
506523
open var isSessionOnly: Bool {
507524
return _sessionOnly
508525
}
509-
526+
510527
/// The domain of the receiver.
511528
///
512529
/// This value specifies URL domain to which the cookie
@@ -535,7 +552,7 @@ open class HTTPCookie : NSObject {
535552
open var isSecure: Bool {
536553
return _secure
537554
}
538-
555+
539556
/// Whether the receiver should only be sent to HTTP servers per RFC 2965
540557
///
541558
/// Cookies may be marked as HTTPOnly by a server (or by a javascript).
@@ -546,7 +563,7 @@ open class HTTPCookie : NSObject {
546563
open var isHTTPOnly: Bool {
547564
return _HTTPOnly
548565
}
549-
566+
550567
/// The comment of the receiver.
551568
///
552569
/// This value specifies a string which is suitable for
@@ -555,7 +572,7 @@ open class HTTPCookie : NSObject {
555572
open var comment: String? {
556573
return _comment
557574
}
558-
575+
559576
/// The comment URL of the receiver.
560577
///
561578
/// This value specifies a URL which is suitable for
@@ -564,7 +581,7 @@ open class HTTPCookie : NSObject {
564581
/*@NSCopying*/ open var commentURL: URL? {
565582
return _commentURL
566583
}
567-
584+
568585
/// The list ports to which the receiver should be sent.
569586
///
570587
/// This value specifies an NSArray of NSNumbers

Foundation/TimeZone.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ extension TimeZone : CustomStringConvertible, CustomDebugStringConvertible, Cust
236236
var c: [(label: String?, value: Any)] = []
237237
c.append((label: "identifier", value: identifier))
238238
c.append((label: "kind", value: _kindDescription))
239-
c.append((label: "abbreviation", value: abbreviation()))
239+
c.append((label: "abbreviation", value: abbreviation() as Any))
240240
c.append((label: "secondsFromGMT", value: secondsFromGMT()))
241241
c.append((label: "isDaylightSavingTime", value: isDaylightSavingTime()))
242242
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)

Foundation/URLComponents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ extension URLQueryItem : CustomStringConvertible, CustomDebugStringConvertible,
368368
public var debugDescription: String {
369369
return self.description
370370
}
371-
371+
372372
public var customMirror: Mirror {
373373
var c: [(label: String?, value: Any)] = []
374374
c.append((label: "name", value: name))
375-
c.append((label: "value", value: value))
375+
c.append((label: "value", value: value as Any))
376376
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
377377
}
378378
}

Foundation/URLRequest.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,23 @@ extension URLRequest : CustomStringConvertible, CustomDebugStringConvertible, Cu
238238
return "url: nil"
239239
}
240240
}
241-
241+
242242
public var debugDescription: String {
243243
return self.description
244244
}
245-
245+
246246
public var customMirror: Mirror {
247247
var c: [(label: String?, value: Any)] = []
248-
c.append((label: "url", value: url))
248+
c.append((label: "url", value: url as Any))
249249
c.append((label: "cachePolicy", value: cachePolicy.rawValue))
250250
c.append((label: "timeoutInterval", value: timeoutInterval))
251-
c.append((label: "mainDocumentURL", value: mainDocumentURL))
251+
c.append((label: "mainDocumentURL", value: mainDocumentURL as Any))
252252
c.append((label: "networkServiceType", value: networkServiceType))
253253
c.append((label: "allowsCellularAccess", value: allowsCellularAccess))
254-
c.append((label: "httpMethod", value: httpMethod))
255-
c.append((label: "allHTTPHeaderFields", value: allHTTPHeaderFields))
256-
c.append((label: "httpBody", value: httpBody))
257-
c.append((label: "httpBodyStream", value: httpBodyStream))
254+
c.append((label: "httpMethod", value: httpMethod as Any))
255+
c.append((label: "allHTTPHeaderFields", value: allHTTPHeaderFields as Any))
256+
c.append((label: "httpBody", value: httpBody as Any))
257+
c.append((label: "httpBodyStream", value: httpBodyStream as Any))
258258
c.append((label: "httpShouldHandleCookies", value: httpShouldHandleCookies))
259259
c.append((label: "httpShouldUsePipelining", value: httpShouldUsePipelining))
260260
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
@@ -265,21 +265,21 @@ extension URLRequest : _ObjectTypeBridgeable {
265265
public static func _getObjectiveCType() -> Any.Type {
266266
return NSURLRequest.self
267267
}
268-
268+
269269
@_semantics("convertToObjectiveC")
270270
public func _bridgeToObjectiveC() -> NSURLRequest {
271271
return _handle._copiedReference()
272272
}
273-
273+
274274
public static func _forceBridgeFromObjectiveC(_ input: NSURLRequest, result: inout URLRequest?) {
275275
result = URLRequest(_bridged: input)
276276
}
277-
277+
278278
public static func _conditionallyBridgeFromObjectiveC(_ input: NSURLRequest, result: inout URLRequest?) -> Bool {
279279
result = URLRequest(_bridged: input)
280280
return true
281281
}
282-
282+
283283
public static func _unconditionallyBridgeFromObjectiveC(_ source: NSURLRequest?) -> URLRequest {
284284
var result: URLRequest? = nil
285285
_forceBridgeFromObjectiveC(source!, result: &result)

0 commit comments

Comments
 (0)