Update for swift 3.

- Convert code to swift 3
- Update alamofire to 4.0.1 for swift 3.
This commit is contained in:
Charlie Qiu
2016-10-02 01:17:07 +08:00
parent 7076523cbd
commit 7a7249b80f
41 changed files with 6976 additions and 4963 deletions

View File

@ -24,24 +24,23 @@
import Foundation
/**
Used to represent whether a request was successful or encountered an error.
- Success: The request and all post processing operations were successful resulting in the serialization of the
provided associated value.
- Failure: The request encountered an error resulting in a failure. The associated values are the original data
provided by the server as well as the error that caused the failure.
*/
public enum Result<Value, Error: ErrorType> {
case Success(Value)
case Failure(Error)
/// Used to represent whether a request was successful or encountered an error.
///
/// - success: The request and all post processing operations were successful resulting in the serialization of the
/// provided associated value.
///
/// - failure: The request encountered an error resulting in a failure. The associated values are the original data
/// provided by the server as well as the error that caused the failure.
public enum Result<Value> {
case success(Value)
case failure(Error)
/// Returns `true` if the result is a success, `false` otherwise.
public var isSuccess: Bool {
switch self {
case .Success:
case .success:
return true
case .Failure:
case .failure:
return false
}
}
@ -54,9 +53,9 @@ public enum Result<Value, Error: ErrorType> {
/// Returns the associated value if the result is a success, `nil` otherwise.
public var value: Value? {
switch self {
case .Success(let value):
case .success(let value):
return value
case .Failure:
case .failure:
return nil
}
}
@ -64,9 +63,9 @@ public enum Result<Value, Error: ErrorType> {
/// Returns the associated error value if the result is a failure, `nil` otherwise.
public var error: Error? {
switch self {
case .Success:
case .success:
return nil
case .Failure(let error):
case .failure(let error):
return error
}
}
@ -75,13 +74,13 @@ public enum Result<Value, Error: ErrorType> {
// MARK: - CustomStringConvertible
extension Result: CustomStringConvertible {
/// The textual representation used when written to an output stream, which includes whether the result was a
/// The textual representation used when written to an output stream, which includes whether the result was a
/// success or failure.
public var description: String {
switch self {
case .Success:
case .success:
return "SUCCESS"
case .Failure:
case .failure:
return "FAILURE"
}
}
@ -94,9 +93,9 @@ extension Result: CustomDebugStringConvertible {
/// success or failure in addition to the value or error.
public var debugDescription: String {
switch self {
case .Success(let value):
case .success(let value):
return "SUCCESS: \(value)"
case .Failure(let error):
case .failure(let error):
return "FAILURE: \(error)"
}
}