Commit 3d534c3b authored by Ben Asher's avatar Ben Asher

Updated Alamofire example for Xcode 7.3

parent 8e2f0ef7
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'Alamofire' s.name = 'Alamofire'
s.version = '3.2.1' s.version = '3.3.0'
s.license = 'MIT' s.license = 'MIT'
s.summary = 'Elegant HTTP Networking in Swift' s.summary = 'Elegant HTTP Networking in Swift'
s.homepage = 'https://github.com/Alamofire/Alamofire' s.homepage = 'https://github.com/Alamofire/Alamofire'
......
...@@ -428,7 +428,6 @@ public class MultipartFormData { ...@@ -428,7 +428,6 @@ public class MultipartFormData {
throw Error.errorWithCode(NSURLErrorCannotOpenFile, failureReason: failureReason) throw Error.errorWithCode(NSURLErrorCannotOpenFile, failureReason: failureReason)
} }
outputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
outputStream.open() outputStream.open()
self.bodyParts.first?.hasInitialBoundary = true self.bodyParts.first?.hasInitialBoundary = true
...@@ -439,7 +438,6 @@ public class MultipartFormData { ...@@ -439,7 +438,6 @@ public class MultipartFormData {
} }
outputStream.close() outputStream.close()
outputStream.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
} }
// MARK: - Private - Body Part Encoding // MARK: - Private - Body Part Encoding
...@@ -476,7 +474,6 @@ public class MultipartFormData { ...@@ -476,7 +474,6 @@ public class MultipartFormData {
private func encodeBodyStreamDataForBodyPart(bodyPart: BodyPart) throws -> NSData { private func encodeBodyStreamDataForBodyPart(bodyPart: BodyPart) throws -> NSData {
let inputStream = bodyPart.bodyStream let inputStream = bodyPart.bodyStream
inputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
inputStream.open() inputStream.open()
var error: NSError? var error: NSError?
...@@ -503,7 +500,6 @@ public class MultipartFormData { ...@@ -503,7 +500,6 @@ public class MultipartFormData {
} }
inputStream.close() inputStream.close()
inputStream.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
if let error = error { if let error = error {
throw error throw error
...@@ -537,7 +533,6 @@ public class MultipartFormData { ...@@ -537,7 +533,6 @@ public class MultipartFormData {
private func writeBodyStreamForBodyPart(bodyPart: BodyPart, toOutputStream outputStream: NSOutputStream) throws { private func writeBodyStreamForBodyPart(bodyPart: BodyPart, toOutputStream outputStream: NSOutputStream) throws {
let inputStream = bodyPart.bodyStream let inputStream = bodyPart.bodyStream
inputStream.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
inputStream.open() inputStream.open()
while inputStream.hasBytesAvailable { while inputStream.hasBytesAvailable {
...@@ -563,7 +558,6 @@ public class MultipartFormData { ...@@ -563,7 +558,6 @@ public class MultipartFormData {
} }
inputStream.close() inputStream.close()
inputStream.removeFromRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
} }
private func writeFinalBoundaryDataForBodyPart( private func writeFinalBoundaryDataForBodyPart(
......
...@@ -114,20 +114,32 @@ public class NetworkReachabilityManager { ...@@ -114,20 +114,32 @@ public class NetworkReachabilityManager {
} }
/** /**
Creates a `NetworkReachabilityManager` instance with the default socket address (`sockaddr_in6`). Creates a `NetworkReachabilityManager` instance with the default socket IPv4 or IPv6 address.
- returns: The new `NetworkReachabilityManager` instance. - returns: The new `NetworkReachabilityManager` instance.
*/ */
public convenience init?() { public convenience init?() {
var address = sockaddr_in6() if #available(iOS 9.0, OSX 10.10, *) {
address.sin6_len = UInt8(sizeofValue(address)) var address = sockaddr_in6()
address.sin6_family = sa_family_t(AF_INET6) address.sin6_len = UInt8(sizeofValue(address))
address.sin6_family = sa_family_t(AF_INET6)
guard let reachability = withUnsafePointer(&address, {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)) guard let reachability = withUnsafePointer(&address, {
}) else { return nil } SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
}) else { return nil }
self.init(reachability: reachability)
self.init(reachability: reachability)
} else {
var address = sockaddr_in()
address.sin_len = UInt8(sizeofValue(address))
address.sin_family = sa_family_t(AF_INET)
guard let reachability = withUnsafePointer(&address, {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
}) else { return nil }
self.init(reachability: reachability)
}
} }
private init(reachability: SCNetworkReachability) { private init(reachability: SCNetworkReachability) {
......
...@@ -244,7 +244,7 @@ public enum ParameterEncoding { ...@@ -244,7 +244,7 @@ public enum ParameterEncoding {
while index != string.endIndex { while index != string.endIndex {
let startIndex = index let startIndex = index
let endIndex = index.advancedBy(batchSize, limit: string.endIndex) let endIndex = index.advancedBy(batchSize, limit: string.endIndex)
let range = Range(start: startIndex, end: endIndex) let range = startIndex..<endIndex
let substring = string.substringWithRange(range) let substring = string.substringWithRange(range)
......
...@@ -484,7 +484,7 @@ extension Request: CustomDebugStringConvertible { ...@@ -484,7 +484,7 @@ extension Request: CustomDebugStringConvertible {
let protectionSpace = NSURLProtectionSpace( let protectionSpace = NSURLProtectionSpace(
host: host, host: host,
port: URL.port?.integerValue ?? 0, port: URL.port?.integerValue ?? 0,
`protocol`: URL.scheme, protocol: URL.scheme,
realm: host, realm: host,
authenticationMethod: NSURLAuthenticationMethodHTTPBasic authenticationMethod: NSURLAuthenticationMethodHTTPBasic
) )
......
...@@ -29,10 +29,10 @@ import Foundation ...@@ -29,10 +29,10 @@ import Foundation
*/ */
public protocol ResponseSerializerType { public protocol ResponseSerializerType {
/// The type of serialized object to be created by this `ResponseSerializerType`. /// The type of serialized object to be created by this `ResponseSerializerType`.
typealias SerializedObject associatedtype SerializedObject
/// The type of error to be created by this `ResponseSerializer` if serialization fails. /// The type of error to be created by this `ResponseSerializer` if serialization fails.
typealias ErrorObject: ErrorType associatedtype ErrorObject: ErrorType
/** /**
A closure used by response handlers that takes a request, response, data and error and returns a result. A closure used by response handlers that takes a request, response, data and error and returns a result.
...@@ -176,8 +176,12 @@ extension Request { ...@@ -176,8 +176,12 @@ extension Request {
- returns: The request. - returns: The request.
*/ */
public func responseData(completionHandler: Response<NSData, NSError> -> Void) -> Self { public func responseData(
return response(responseSerializer: Request.dataResponseSerializer(), completionHandler: completionHandler) queue queue: dispatch_queue_t? = nil,
completionHandler: Response<NSData, NSError> -> Void)
-> Self
{
return response(queue: queue, responseSerializer: Request.dataResponseSerializer(), completionHandler: completionHandler)
} }
} }
...@@ -240,11 +244,13 @@ extension Request { ...@@ -240,11 +244,13 @@ extension Request {
- returns: The request. - returns: The request.
*/ */
public func responseString( public func responseString(
encoding encoding: NSStringEncoding? = nil, queue queue: dispatch_queue_t? = nil,
encoding: NSStringEncoding? = nil,
completionHandler: Response<String, NSError> -> Void) completionHandler: Response<String, NSError> -> Void)
-> Self -> Self
{ {
return response( return response(
queue: queue,
responseSerializer: Request.stringResponseSerializer(encoding: encoding), responseSerializer: Request.stringResponseSerializer(encoding: encoding),
completionHandler: completionHandler completionHandler: completionHandler
) )
...@@ -296,11 +302,13 @@ extension Request { ...@@ -296,11 +302,13 @@ extension Request {
- returns: The request. - returns: The request.
*/ */
public func responseJSON( public func responseJSON(
options options: NSJSONReadingOptions = .AllowFragments, queue queue: dispatch_queue_t? = nil,
options: NSJSONReadingOptions = .AllowFragments,
completionHandler: Response<AnyObject, NSError> -> Void) completionHandler: Response<AnyObject, NSError> -> Void)
-> Self -> Self
{ {
return response( return response(
queue: queue,
responseSerializer: Request.JSONResponseSerializer(options: options), responseSerializer: Request.JSONResponseSerializer(options: options),
completionHandler: completionHandler completionHandler: completionHandler
) )
...@@ -354,11 +362,13 @@ extension Request { ...@@ -354,11 +362,13 @@ extension Request {
- returns: The request. - returns: The request.
*/ */
public func responsePropertyList( public func responsePropertyList(
options options: NSPropertyListReadOptions = NSPropertyListReadOptions(), queue queue: dispatch_queue_t? = nil,
options: NSPropertyListReadOptions = NSPropertyListReadOptions(),
completionHandler: Response<AnyObject, NSError> -> Void) completionHandler: Response<AnyObject, NSError> -> Void)
-> Self -> Self
{ {
return response( return response(
queue: queue,
responseSerializer: Request.propertyListResponseSerializer(options: options), responseSerializer: Request.propertyListResponseSerializer(options: options),
completionHandler: completionHandler completionHandler: completionHandler
) )
......
...@@ -46,7 +46,7 @@ class DetailViewController: UITableViewController { ...@@ -46,7 +46,7 @@ class DetailViewController: UITableViewController {
override func awakeFromNib() { override func awakeFromNib() {
super.awakeFromNib() super.awakeFromNib()
self.refreshControl?.addTarget(self, action: "refresh", forControlEvents: .ValueChanged) self.refreshControl?.addTarget(self, action: #selector(DetailViewController.refresh), forControlEvents: .ValueChanged)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment