Error

作者: 幸运的小强本人 | 来源:发表于2016-02-27 17:04 被阅读57次

    // The Error struct provides a convenience for
    // creating custom Alamofire NSErrors.

    public struct Error {
      // The domain used for creating all Alamofire errors.
      public static let Domain = "com.alamofire.error"
    
      // The custom error codes generated by Alamofire.
      public enum Code: Int {
        case InputStreamReadFailed    = -6000
        case OutputStreamWriteFailed  = -6001
        case ContentTypeValidationFailed = -6002
        case StatusCodeValidationFailed = -6003
        case DataSerializationFailed = 6004
        case StringSerializationFailed = 6005
        case JSONSerializationFailed = -6006
        case PropertyListSerializationFailed = -6007
    }
    
    /**
      Creates an NSError with the given error code and failure reason
      \- parameter code: The error code
      \- parameter failureReason: the failure reason
    
      \- returns: An "NSError" with the given error code and failure reason
      */
      public static func errorWithCode(code: Code failureReason: String)-> NSError {
          return errorWithCode(code.rawValue, failureReason: failureReason)
      }
    
     /**
        Creates an "NSError" with the given error code and failure reason
        \- parameter code: The error code
        \- parameter failureReason: The failure reason
    
        \- returns: An "NSError" with the given error code and failure reason
    */
    public static func errorWithCode(code: Int, failureReason: String)->NSError {
      let userInfo = [NSLocalizedFailureReasonErrorKey: failureReason]
    
        return NSError(domain: Domain, code: code, userInfo:userInfo)
      }
    }
    

    相关文章

      网友评论

          本文标题:Error

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