UnboxedAlamofire 2.0.4

UnboxedAlamofire 2.0.4

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布上次发布2017 年 10 月
SwiftSwift 版本3.0
SPM支持 SPM

Serhii Butenko 维护。



 
依赖
Alamofire~> 4.1
Unbox~> 2.0
 

  • Serhii Butenko

UnboxedAlamofire




Alamofire + Unbox:将 JSON 下载并解码到 swift 对象的道路最简便。

特点

  • 单元测试
  • 完整文档
  • 将响应映射到对象
  • 将响应映射到对象数组
  • Keypaths
  • 嵌套 keypaths
  • 对于 Swift 2.x 使用 v. 1.x 以及 swift2 分支
  • 对于 Swift 3.x 则使用 v. 2.x

使用方法

您请求的对象必须满足 Unboxable 协议。

获取对象

Alamofire.request(url, method: .get).responseObject { (response: DataResponse<Candy>) in
    // handle response
    let candy = response.result.value
    
    // handle error
    if let error = response.result.error as? UnboxedAlamofireError {
        print("error: \(error.description)")
    }
}

获取数组

Alamofire.request(url, method: .get).responseArray { (response: DataResponse<[Candy]>) in
    // handle response
    let candies = response.result.value
    
    // handle error
    if let error = response.result.error as? UnboxedAlamofireError {
        print("error: \(error.description)")
    }
}

KeyPath

您也可以在请求中指定一个 keypath

Alamofire.request(url, method: .get).responseObject(keyPath: "response") { (response: DataResponse<Candy>) in
    // handle response
    let candy = response.result.value
    
    // handle error
    if let error = response.result.error as? UnboxedAlamofireError {
        print("error: \(error.description)")
    }
}

安装