Skip to content

Fix Any? -> Any build warnings #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 66 additions & 49 deletions Foundation/NSHTTPCookie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,42 @@ extension HTTPCookiePropertyKey {

/// Key for cookie value
public static let value = HTTPCookiePropertyKey(rawValue: "Value")

/// Key for cookie origin URL
public static let originURL = HTTPCookiePropertyKey(rawValue: "OriginURL")

/// Key for cookie version
public static let version = HTTPCookiePropertyKey(rawValue: "Version")

/// Key for cookie domain
public static let domain = HTTPCookiePropertyKey(rawValue: "Domain")

/// Key for cookie path
public static let path = HTTPCookiePropertyKey(rawValue: "Path")

/// Key for cookie secure flag
public static let secure = HTTPCookiePropertyKey(rawValue: "Secure")

/// Key for cookie expiration date
public static let expires = HTTPCookiePropertyKey(rawValue: "Expires")

/// Key for cookie comment text
public static let comment = HTTPCookiePropertyKey(rawValue: "Comment")

/// Key for cookie comment URL
public static let commentURL = HTTPCookiePropertyKey(rawValue: "CommentURL")

/// Key for cookie discard (session-only) flag
public static let discard = HTTPCookiePropertyKey(rawValue: "Discard")

/// Key for cookie maximum age (an alternate way of specifying the expiration)
public static let maximumAge = HTTPCookiePropertyKey(rawValue: "Max-Age")

/// Key for cookie ports
public static let port = HTTPCookiePropertyKey(rawValue: "Port")

// For Cocoa compatibility
internal static let created = HTTPCookiePropertyKey(rawValue: "Created")
}

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

static let _attributes: [HTTPCookiePropertyKey] = [.name, .value, .originURL, .version,
.domain, .path, .secure, .expires,
.comment, .commentURL, .discard, .maximumAge,
.port]
static let _attributes: [HTTPCookiePropertyKey]
= [.name, .value, .originURL, .version, .domain,
.path, .secure, .expires, .comment, .commentURL,
.discard, .maximumAge, .port]

/// Initialize a NSHTTPCookie object with a dictionary of parameters
///
Expand Down Expand Up @@ -268,7 +271,7 @@ open class HTTPCookie : NSObject {
version = 0
}
_version = version

if let portString = properties[.port] as? String, _version == 1 {
_portList = portString.characters
.split(separator: ",")
Expand Down Expand Up @@ -300,8 +303,7 @@ open class HTTPCookie : NSObject {
} else {
_expiresDate = nil
}



if let discardString = properties[.discard] as? String {
_sessionOnly = discardString == "TRUE"
} else {
Expand All @@ -321,23 +323,38 @@ open class HTTPCookie : NSObject {
}
}
_HTTPOnly = false
_properties = [.comment : properties[.comment],
.commentURL : properties[.commentURL],
HTTPCookiePropertyKey(rawValue: "Created") : Date().timeIntervalSinceReferenceDate, // Cocoa Compatibility
.discard : _sessionOnly,
.domain : _domain,
.expires : _expiresDate,
.maximumAge : properties[.maximumAge],
.name : _name,
.originURL : properties[.originURL],
.path : _path,
.port : _portList,
.secure : _secure,
.value : _value,
.version : _version


_properties = [
.created : Date().timeIntervalSinceReferenceDate, // Cocoa Compatibility
.discard : _sessionOnly,
.domain : _domain,
.name : _name,
.path : _path,
.secure : _secure,
.value : _value,
.version : _version
]
if let comment = properties[.comment] {
_properties[.comment] = comment
}
if let commentURL = properties[.commentURL] {
_properties[.commentURL] = commentURL
}
if let expires = properties[.expires] {
_properties[.expires] = expires
}
if let maximumAge = properties[.maximumAge] {
_properties[.maximumAge] = maximumAge
}
if let originURL = properties[.originURL] {
_properties[.originURL] = originURL
}
if let _portList = _portList {
_properties[.port] = _portList
}
}

/// Return a dictionary of header fields that can be used to add the
/// specified cookies to the request.
///
Expand All @@ -355,7 +372,7 @@ open class HTTPCookie : NSObject {
}
return ["Cookie": cookieString]
}

/// Return an array of cookies parsed from the specified response header fields and URL.
///
/// This method will ignore irrelevant header fields so
Expand All @@ -371,7 +388,7 @@ open class HTTPCookie : NSObject {
// names and values. This implementation takes care of multiple cookies in the same field, however it doesn't
//support commas and semicolons in names and values(except for dates)

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

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

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

//bake the cookies
var httpCookies: [HTTPCookie] = []
Expand All @@ -392,9 +409,9 @@ open class HTTPCookie : NSObject {
httpCookies.append(aCookie)
}
}

return httpCookies
}
}

//Bake a cookie
private class func createHttpCookie(url: URL, pairs: ArraySlice<String>) -> HTTPCookie? {
Expand All @@ -403,20 +420,20 @@ open class HTTPCookie : NSObject {
let name = pair.components(separatedBy: "=")[0]
var value = pair.components(separatedBy: "\(name)=")[1] //a value can have an "="
if canonicalize(name) == .expires {
value = value.insertComma(at: 3) //re-insert the comma
value = value.insertComma(at: 3) //re-insert the comma
}
properties[canonicalize(name)] = value
}

//if domain wasn't provided use the URL
if properties[.domain] == nil {
properties[.domain] = url.absoluteString
}

//the default Path is "/"
if properties[.path] == nil {
properties[.path] = "/"
}
}

return HTTPCookie(properties: properties)
}
Expand Down Expand Up @@ -470,25 +487,25 @@ open class HTTPCookie : NSObject {
open var properties: [HTTPCookiePropertyKey : Any]? {
return _properties
}

/// The version of the receiver.
///
/// Version 0 maps to "old-style" Netscape cookies.
/// Version 1 maps to RFC2965 cookies. There may be future versions.
open var version: Int {
return _version
}

/// The name of the receiver.
open var name: String {
return _name
}

/// The value of the receiver.
open var value: String {
return _value
}

/// Returns The expires date of the receiver.
///
/// The expires date is the date when the cookie should be
Expand All @@ -497,7 +514,7 @@ open class HTTPCookie : NSObject {
/*@NSCopying*/ open var expiresDate: Date? {
return _expiresDate
}

/// Whether the receiver is session-only.
///
/// `true` if this receiver should be discarded at the end of the
Expand All @@ -506,7 +523,7 @@ open class HTTPCookie : NSObject {
open var isSessionOnly: Bool {
return _sessionOnly
}

/// The domain of the receiver.
///
/// This value specifies URL domain to which the cookie
Expand Down Expand Up @@ -535,7 +552,7 @@ open class HTTPCookie : NSObject {
open var isSecure: Bool {
return _secure
}

/// Whether the receiver should only be sent to HTTP servers per RFC 2965
///
/// Cookies may be marked as HTTPOnly by a server (or by a javascript).
Expand All @@ -546,7 +563,7 @@ open class HTTPCookie : NSObject {
open var isHTTPOnly: Bool {
return _HTTPOnly
}

/// The comment of the receiver.
///
/// This value specifies a string which is suitable for
Expand All @@ -555,7 +572,7 @@ open class HTTPCookie : NSObject {
open var comment: String? {
return _comment
}

/// The comment URL of the receiver.
///
/// This value specifies a URL which is suitable for
Expand All @@ -564,7 +581,7 @@ open class HTTPCookie : NSObject {
/*@NSCopying*/ open var commentURL: URL? {
return _commentURL
}

/// The list ports to which the receiver should be sent.
///
/// This value specifies an NSArray of NSNumbers
Expand Down
2 changes: 1 addition & 1 deletion Foundation/TimeZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ extension TimeZone : CustomStringConvertible, CustomDebugStringConvertible, Cust
var c: [(label: String?, value: Any)] = []
c.append((label: "identifier", value: identifier))
c.append((label: "kind", value: _kindDescription))
c.append((label: "abbreviation", value: abbreviation()))
c.append((label: "abbreviation", value: abbreviation() as Any))
c.append((label: "secondsFromGMT", value: secondsFromGMT()))
c.append((label: "isDaylightSavingTime", value: isDaylightSavingTime()))
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
Expand Down
4 changes: 2 additions & 2 deletions Foundation/URLComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ extension URLQueryItem : CustomStringConvertible, CustomDebugStringConvertible,
public var debugDescription: String {
return self.description
}

public var customMirror: Mirror {
var c: [(label: String?, value: Any)] = []
c.append((label: "name", value: name))
c.append((label: "value", value: value))
c.append((label: "value", value: value as Any))
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
}
}
Expand Down
24 changes: 12 additions & 12 deletions Foundation/URLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,23 @@ extension URLRequest : CustomStringConvertible, CustomDebugStringConvertible, Cu
return "url: nil"
}
}

public var debugDescription: String {
return self.description
}

public var customMirror: Mirror {
var c: [(label: String?, value: Any)] = []
c.append((label: "url", value: url))
c.append((label: "url", value: url as Any))
c.append((label: "cachePolicy", value: cachePolicy.rawValue))
c.append((label: "timeoutInterval", value: timeoutInterval))
c.append((label: "mainDocumentURL", value: mainDocumentURL))
c.append((label: "mainDocumentURL", value: mainDocumentURL as Any))
c.append((label: "networkServiceType", value: networkServiceType))
c.append((label: "allowsCellularAccess", value: allowsCellularAccess))
c.append((label: "httpMethod", value: httpMethod))
c.append((label: "allHTTPHeaderFields", value: allHTTPHeaderFields))
c.append((label: "httpBody", value: httpBody))
c.append((label: "httpBodyStream", value: httpBodyStream))
c.append((label: "httpMethod", value: httpMethod as Any))
c.append((label: "allHTTPHeaderFields", value: allHTTPHeaderFields as Any))
c.append((label: "httpBody", value: httpBody as Any))
c.append((label: "httpBodyStream", value: httpBodyStream as Any))
c.append((label: "httpShouldHandleCookies", value: httpShouldHandleCookies))
c.append((label: "httpShouldUsePipelining", value: httpShouldUsePipelining))
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
Expand All @@ -265,21 +265,21 @@ extension URLRequest : _ObjectTypeBridgeable {
public static func _getObjectiveCType() -> Any.Type {
return NSURLRequest.self
}

@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSURLRequest {
return _handle._copiedReference()
}

public static func _forceBridgeFromObjectiveC(_ input: NSURLRequest, result: inout URLRequest?) {
result = URLRequest(_bridged: input)
}

public static func _conditionallyBridgeFromObjectiveC(_ input: NSURLRequest, result: inout URLRequest?) -> Bool {
result = URLRequest(_bridged: input)
return true
}

public static func _unconditionallyBridgeFromObjectiveC(_ source: NSURLRequest?) -> URLRequest {
var result: URLRequest? = nil
_forceBridgeFromObjectiveC(source!, result: &result)
Expand Down
Loading