NAlamofire 2.0.17

NAlamofire 2.0.17

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

Nguyen Phu Nghia 维护。



 
依赖项
NRxSwift>= 0
Alamofire>= 0
SwiftyJSON>= 0
ObjectMapper>= 0
NLogProtocol>= 0
 

NAlamofire 2.0.17

  • 作者
  • Nghia Nguyen

NAlamofire

NAlamofire - 通过 RxSwift 以轻松的方式在几行代码中将请求直接转换为对象、数组对象。它是 Alamofire 的包装器。

引用库:1. ObjectMapper 2. NRxSwift 3. SwiftyJSON 4. NLogProtocol

安装

Pod

use_frameworks!
pod 'NAlamofire'

用法

import ObjectMapper
import NAlamofire

//Object must be conformed to Mappable or NKMappable.
struct Item: Mappable {
    private enum Key: String, NKAlamofireKey {
        case id, name
    }

    var id: Int = 0
    var name: String = ""

    init?(_ map: Map) {}

    mutating func mapping(map: Map) {
        id <- map[Key.id]
        name <- map[Key.name]
    }
}

//create API client
let apiClient = NKApiClient(host: "https://server.com")

// create items observable
let itemsObservable: Observable[Item]> = apiClient.get("items")

//subscrible observables to get objects
itemsObservable.subscrible(onNext: { items in
})

NKApiClient

这是 Alamofire Manager 的包装器,目的是帮助您更容易地发出请求(get/post/put/delete)。支持 multipart/formdata 类型。

公共 API

    public func setDefaultHeader(key:value:)
    public func removeDefaultHeader(key:)
    public func extraUserAgent()
    open func bussinessErrorFromResponse(_:) // override to customize bussinessError. See also at NKNetworkErrorType.
订阅通知名称 NKApiClient.kUnauthorizedNotificationName 以处理未授权案例。

打印请求和响应数据

    import NLogProtocol

    struct CustomNLog: NLogProtocol {//See apis at NLogProtocol}

    NKLOG = CustomNLog.self

感谢 @khoinguyenvu 和 @trinhngocthuyen 对您的贡献。