美文网首页
Alamofire源码解析 - Result

Alamofire源码解析 - Result

作者: wanglj | 来源:发表于2017-04-07 14:05 被阅读0次

    对应response中的result属性

    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:
                return true
            case .failure:
                return false
            }
        }
    
        /// Returns `true` if the result is a failure, `false` otherwise.
        public var isFailure: Bool {
            return !isSuccess
        }
    
        /// Returns the associated value if the result is a success, `nil` otherwise.
        public var value: Value? {
            switch self {
            case .success(let value):
                return value
            case .failure:
                return nil
            }
        }
    
        /// Returns the associated error value if the result is a failure, `nil` otherwise.
        public var error: Error? {
            switch self {
            case .success:
                return nil
            case .failure(let error):
                return error
            }
        }
    }
    
    

    相关文章

      网友评论

          本文标题:Alamofire源码解析 - Result

          本文链接:https://www.haomeiwen.com/subject/yndhattx.html