Error

// 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)
  }
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,552評論 5 6
  • 窗臺上透著光 微微的光描繪著淡淡的憂傷 那憂傷在心房蕩漾 不說話 只是岸邊的流水 映著你的模樣 匆匆的過往 隨雪飄...
    桒惪閱讀 266評論 0 2
  • 文/鴻運(河北) 時光就這樣溜走 靜悄悄 總以為有大把的青春揮毫 等秋風卷走最后的落葉 才懂得自己是時間的玩偶 信...
    HONGYUNDANGTOU閱讀 256評論 10 15
  • 街邊、象棋、看客, 棋逢對手; 一個謀定就動、 一個悠然自得, 贏今天意氣風發, 輸不過一盤象棋, 輸贏都是生活。...
    心境隨緣毅閱讀 184評論 0 0
  • 1從哪種書體入門 學習書法應該從哪種書體入手呢?自古也是爭論不休,蘇東坡在《書說》里說:“書法,備于正書,溢而為行...
    很久沒吃飯了閱讀 468評論 0 4