Skip to content

Commit

Permalink
Xcode 8 Beta 6 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
elm4ward committed Aug 16, 2016
1 parent bfef139 commit 7f74c6d
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 172 deletions.
6 changes: 3 additions & 3 deletions Source/Alamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ public func upload(_ stream: InputStream, with urlRequest: URLRequestConvertible
/// - parameter headers: The HTTP headers. `nil` by default.
/// - parameter encodingCompletion: The closure called when the `MultipartFormData` encoding is complete.
public func upload(
multipartFormData: (MultipartFormData) -> Void,
multipartFormData: @escaping (MultipartFormData) -> Void,
usingThreshold encodingMemoryThreshold: UInt64 = SessionManager.multipartFormDataEncodingMemoryThreshold,
to urlString: URLStringConvertible,
withMethod method: HTTPMethod,
headers: [String: String]? = nil,
encodingCompletion: ((SessionManager.MultipartFormDataEncodingResult) -> Void)?)
encodingCompletion: (@escaping (SessionManager.MultipartFormDataEncodingResult) -> Void)?)
{
return SessionManager.default.upload(
multipartFormData: multipartFormData,
Expand Down Expand Up @@ -372,7 +372,7 @@ public func upload(
/// - parameter urlRequest: The URL request.
/// - parameter encodingCompletion: The closure called when the `MultipartFormData` encoding is complete.
public func upload(
multipartFormData: (MultipartFormData) -> Void,
multipartFormData: @escaping (MultipartFormData) -> Void,
usingThreshold encodingMemoryThreshold: UInt64 = SessionManager.multipartFormDataEncodingMemoryThreshold,
with urlRequest: URLRequestConvertible,
encodingCompletion: ((SessionManager.MultipartFormDataEncodingResult) -> Void)?)
Expand Down
20 changes: 10 additions & 10 deletions Source/MultipartFormData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ public class MultipartFormData {
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorBadURL, failureReason: failureReason)
}

let outputStream: NSOutputStream
let outputStream: OutputStream

if let possibleOutputStream = NSOutputStream(url: fileURL, append: false) {
if let possibleOutputStream = OutputStream(url: fileURL, append: false) {
outputStream = possibleOutputStream
} else {
let failureReason = "Failed to create an output stream with the given URL: \(fileURL)"
Expand Down Expand Up @@ -478,24 +478,24 @@ public class MultipartFormData {

// MARK: - Private - Writing Body Part to Output Stream

private func write(_ bodyPart: BodyPart, to outputStream: NSOutputStream) throws {
private func write(_ bodyPart: BodyPart, to outputStream: OutputStream) throws {
try writeInitialBoundaryData(for: bodyPart, to: outputStream)
try writeHeaderData(for: bodyPart, to: outputStream)
try writeBodyStream(for: bodyPart, to: outputStream)
try writeFinalBoundaryData(for: bodyPart, to: outputStream)
}

private func writeInitialBoundaryData(for bodyPart: BodyPart, to outputStream: NSOutputStream) throws {
private func writeInitialBoundaryData(for bodyPart: BodyPart, to outputStream: OutputStream) throws {
let initialData = bodyPart.hasInitialBoundary ? initialBoundaryData() : encapsulatedBoundaryData()
return try write(initialData, to: outputStream)
}

private func writeHeaderData(for bodyPart: BodyPart, to outputStream: NSOutputStream) throws {
private func writeHeaderData(for bodyPart: BodyPart, to outputStream: OutputStream) throws {
let headerData = encodeHeaders(for: bodyPart)
return try write(headerData, to: outputStream)
}

private func writeBodyStream(for bodyPart: BodyPart, to outputStream: NSOutputStream) throws {
private func writeBodyStream(for bodyPart: BodyPart, to outputStream: OutputStream) throws {
let inputStream = bodyPart.bodyStream
inputStream.open()

Expand Down Expand Up @@ -524,22 +524,22 @@ public class MultipartFormData {
inputStream.close()
}

private func writeFinalBoundaryData(for bodyPart: BodyPart, to outputStream: NSOutputStream) throws {
private func writeFinalBoundaryData(for bodyPart: BodyPart, to outputStream: OutputStream) throws {
if bodyPart.hasFinalBoundary {
return try write(finalBoundaryData(), to: outputStream)
}
}

// MARK: - Private - Writing Buffered Data to Output Stream

private func write(_ data: Data, to outputStream: NSOutputStream) throws {
private func write(_ data: Data, to outputStream: OutputStream) throws {
var buffer = [UInt8](repeating: 0, count: data.count)
(data as NSData).getBytes(&buffer, length: data.count)

return try write(&buffer, to: outputStream)
}

private func write(_ buffer: inout [UInt8], to outputStream: NSOutputStream) throws {
private func write(_ buffer: inout [UInt8], to outputStream: OutputStream) throws {
var bytesToWrite = buffer.count

while bytesToWrite > 0 {
Expand Down Expand Up @@ -570,7 +570,7 @@ public class MultipartFormData {

private func mimeType(forPathExtension pathExtension: String) -> String {
if
let id = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension, nil)?.takeRetainedValue(),
let id = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension as CFString, nil)?.takeRetainedValue(),
let contentType = UTTypeCopyPreferredTagWithClass(id, kUTTagClassMIMEType)?.takeRetainedValue()
{
return contentType as String
Expand Down
17 changes: 11 additions & 6 deletions Source/NetworkReachabilityManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,19 @@ public class NetworkReachabilityManager {
/// - returns: The new `NetworkReachabilityManager` instance.
public convenience init?() {
var address = sockaddr_in()
address.sin_len = UInt8(sizeofValue(address))
address.sin_len = UInt8(MemoryLayout<sockaddr_in>.size)
address.sin_family = sa_family_t(AF_INET)

guard let reachability = withUnsafePointer(&address, {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
}) else { return nil }
let pointer = UnsafeMutablePointer<sockaddr_in>.allocate(capacity: MemoryLayout<sockaddr_in>.size)
pointer.initialize(to: address)
let pointer2 = UnsafePointer(pointer)
let reachability = pointer2.withMemoryRebound(to: sockaddr.self, capacity: MemoryLayout<sockaddr>.size) {
return SCNetworkReachabilityCreateWithAddress(nil, $0)
}
//
guard let r = reachability else { return nil }

self.init(reachability: reachability)
self.init(reachability: r)
}

private init(reachability: SCNetworkReachability) {
Expand All @@ -151,7 +156,7 @@ public class NetworkReachabilityManager {
@discardableResult
public func startListening() -> Bool {
var context = SCNetworkReachabilityContext(version: 0, info: nil, retain: nil, release: nil, copyDescription: nil)
context.info = UnsafeMutablePointer(Unmanaged.passUnretained(self).toOpaque())
//context.info = UnsafeMutablePointer(Unmanaged.passUnretained(self).toOpaque())

let callbackEnabled = SCNetworkReachabilitySetCallback(
reachability,
Expand Down
10 changes: 6 additions & 4 deletions Source/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,23 @@ extension Request: CustomDebugStringConvertible {
let cookieStorage = session.configuration.httpCookieStorage,
let cookies = cookieStorage.cookies(for: URL), !cookies.isEmpty
{
let string = cookies.reduce("") { $0 + "\($1.name)=\($1.value ?? String());" }
let string = cookies.reduce("") { $0 + "\($1.name)=\($1.value);" }
components.append("-b \"\(string.substring(to: string.characters.index(before: string.endIndex)))\"")
}
}

var headers: [NSObject: AnyObject] = [:]
var headers: [String: Any] = [:]

if let additionalHeaders = session.configuration.httpAdditionalHeaders {
for (field, value) in additionalHeaders where field != "Cookie" {
for (field, value) in additionalHeaders {
guard let field = field as? String, field != "Cookie" else { continue }
headers[field] = value
}
}

if let headerFields = request.allHTTPHeaderFields {
for (field, value) in headerFields where field != "Cookie" {
for (field, value) in headerFields {
guard let field = field as? String, field != "Cookie" else { continue }
headers[field] = value
}
}
Expand Down
20 changes: 10 additions & 10 deletions Source/ResponseSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public struct ResponseSerializer<Value, Error: Swift.Error>: ResponseSerializerT
/// - parameter serializeResponse: The closure used to serialize the response.
///
/// - returns: The new generic response serializer instance.
public init(serializeResponse: (URLRequest?, HTTPURLResponse?, Data?, NSError?) -> Result<Value, Error>) {
public init(serializeResponse: @escaping (URLRequest?, HTTPURLResponse?, Data?, NSError?) -> Result<Value, Error>) {
self.serializeResponse = serializeResponse
}
}
Expand All @@ -73,7 +73,7 @@ extension Request {
@discardableResult
public func response(
queue: DispatchQueue? = nil,
completionHandler: (URLRequest?, HTTPURLResponse?, Data?, NSError?) -> Void)
completionHandler: @escaping (URLRequest?, HTTPURLResponse?, Data?, NSError?) -> Void)
-> Self
{
delegate.queue.addOperation {
Expand All @@ -97,7 +97,7 @@ extension Request {
public func response<T: ResponseSerializerType>(
queue: DispatchQueue? = nil,
responseSerializer: T,
completionHandler: (Response<T.SerializedObject, T.ErrorObject>) -> Void)
completionHandler: @escaping (Response<T.SerializedObject, T.ErrorObject>) -> Void)
-> Self
{
delegate.queue.addOperation {
Expand Down Expand Up @@ -161,7 +161,7 @@ extension Request {
///
/// - returns: The request.
@discardableResult
public func responseData(queue: DispatchQueue? = nil, completionHandler: (Response<Data, NSError>) -> Void) -> Self {
public func responseData(queue: DispatchQueue? = nil, completionHandler: @escaping (Response<Data, NSError>) -> Void) -> Self {
return response(queue: queue, responseSerializer: Request.dataResponseSerializer(), completionHandler: completionHandler)
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ extension Request {

if let encodingName = response?.textEncodingName, convertedEncoding == nil {
convertedEncoding = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(
CFStringConvertIANACharSetNameToEncoding(encodingName))
CFStringConvertIANACharSetNameToEncoding(encodingName as CFString!))
)
}

Expand Down Expand Up @@ -220,7 +220,7 @@ extension Request {
public func responseString(
queue: DispatchQueue? = nil,
encoding: String.Encoding? = nil,
completionHandler: (Response<String, NSError>) -> Void)
completionHandler: @escaping (Response<String, NSError>) -> Void)
-> Self
{
return response(
Expand Down Expand Up @@ -257,7 +257,7 @@ extension Request {

do {
let JSON = try JSONSerialization.jsonObject(with: validData, options: options)
return .success(JSON)
return .success(JSON as AnyObject)
} catch {
return .failure(error as NSError)
}
Expand All @@ -274,7 +274,7 @@ extension Request {
public func responseJSON(
queue: DispatchQueue? = nil,
options: JSONSerialization.ReadingOptions = .allowFragments,
completionHandler: (Response<AnyObject, NSError>) -> Void)
completionHandler: @escaping (Response<AnyObject, NSError>) -> Void)
-> Self
{
return response(
Expand Down Expand Up @@ -311,7 +311,7 @@ extension Request {

do {
let plist = try PropertyListSerialization.propertyList(from: validData, options: options, format: nil)
return .success(plist)
return .success(plist as AnyObject)
} catch {
return .failure(error as NSError)
}
Expand All @@ -330,7 +330,7 @@ extension Request {
public func responsePropertyList(
queue: DispatchQueue? = nil,
options: PropertyListSerialization.ReadOptions = PropertyListSerialization.ReadOptions(),
completionHandler: (Response<AnyObject, NSError>) -> Void)
completionHandler: @escaping (Response<AnyObject, NSError>) -> Void)
-> Self
{
return response(
Expand Down
16 changes: 8 additions & 8 deletions Source/ServerTrustPolicy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public enum ServerTrustPolicy {
case pinCertificates(certificates: [SecCertificate], validateCertificateChain: Bool, validateHost: Bool)
case pinPublicKeys(publicKeys: [SecKey], validateCertificateChain: Bool, validateHost: Bool)
case disableEvaluation
case customEvaluation((serverTrust: SecTrust, host: String) -> Bool)
case customEvaluation((_ serverTrust: SecTrust, _ host: String) -> Bool)

// MARK: - Bundle Location

Expand All @@ -124,12 +124,12 @@ public enum ServerTrustPolicy {

let paths = Set([".cer", ".CER", ".crt", ".CRT", ".der", ".DER"].map { fileExtension in
bundle.paths(forResourcesOfType: fileExtension, inDirectory: nil)
}.flatten())
}.joined())

for path in paths {
if
let certificateData = try? Data(contentsOf: URL(fileURLWithPath: path)),
let certificate = SecCertificateCreateWithData(nil, certificateData)
let certificate = SecCertificateCreateWithData(nil, certificateData as CFData)
{
certificates.append(certificate)
}
Expand Down Expand Up @@ -169,15 +169,15 @@ public enum ServerTrustPolicy {
switch self {
case let .performDefaultEvaluation(validateHost):
let policy = SecPolicyCreateSSL(true, validateHost ? host as CFString : nil)
SecTrustSetPolicies(serverTrust, [policy])
SecTrustSetPolicies(serverTrust, [policy] as AnyObject)

serverTrustIsValid = trustIsValid(serverTrust)
case let .pinCertificates(pinnedCertificates, validateCertificateChain, validateHost):
if validateCertificateChain {
let policy = SecPolicyCreateSSL(true, validateHost ? host as CFString : nil)
SecTrustSetPolicies(serverTrust, [policy])
SecTrustSetPolicies(serverTrust, [policy] as AnyObject)

SecTrustSetAnchorCertificates(serverTrust, pinnedCertificates)
SecTrustSetAnchorCertificates(serverTrust, pinnedCertificates as CFArray)
SecTrustSetAnchorCertificatesOnly(serverTrust, true)

serverTrustIsValid = trustIsValid(serverTrust)
Expand All @@ -199,7 +199,7 @@ public enum ServerTrustPolicy {

if validateCertificateChain {
let policy = SecPolicyCreateSSL(true, validateHost ? host as CFString : nil)
SecTrustSetPolicies(serverTrust, [policy])
SecTrustSetPolicies(serverTrust, [policy] as AnyObject)

certificateChainEvaluationPassed = trustIsValid(serverTrust)
}
Expand All @@ -217,7 +217,7 @@ public enum ServerTrustPolicy {
case .disableEvaluation:
serverTrustIsValid = true
case let .customEvaluation(closure):
serverTrustIsValid = closure(serverTrust: serverTrust, host: host)
serverTrustIsValid = closure(serverTrust, host)
}

return serverTrustIsValid
Expand Down

0 comments on commit 7f74c6d

Please sign in to comment.