AlamofireReactiveExtensions 3.0.0-alpha.1

AlamofireReactiveExtensions 3.0.0-alpha.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最新发布2017年10月
SwiftSwift 版本4.0
SPM支持 SPM

George Kaimakas 维护。



 
依赖关系
Alamofire~> 4.0
ReactiveSwift~> 3.0.0-alpha.1
 

  • gkaimakas

AlamofireReactiveExtensions

想要使用 ReactiveSwift 配合 Alamofire?AlamofireReactiveExtensions 为您提供了解决方案。它提供了一组扩展,这些扩展将 Alamofire 的回调与 ReactiveSwift 的 SignalProducers 相桥接。您甚至可以轻松将 ReactiveSwift 的操作符应用于您的响应,合并多个请求或按顺序执行请求。

该项目目前提供的扩展包括:1. SessionManager 2. DataRequest 3. DownloadRequest 4. UploadRequest

对于请求 AlamofireReactiveExtensions 提供以下函数:1. request(queue:) 2. request(queue:, responseSerializer) 3. responseData(queue:) 4. responseString(queue:, encoding:) 5. responseJSON(queue:s options:) 6. responsePropertyList(queue:, options:)

SessionManager 支持以下函数:1. request(_:, method:, parameters:, encoding:, headers:) 2. request(_:) 3. download(_:, method:, parameters:, encoding:, headers:, to) 4. download(_:, to:) 5. download(resumingWith:, to:) 6. upload(_:, to:, method:, headers:) 7. upload(_:, with:) 8. upload(_:, to:, method:, headers: ) 9. upload(_:, with:) 10. upload(_:, to:, method:, headers:) 11. stream(withHostName:, port:)

安装

AlamofireReactiveExtensions 通过 CocoaPods 提供。

pod 'AlamofireReactiveExtensions'

用法

ReactiveSwift 扩展位于 SessionManagerDataRequestDownloadRequestUploadRequest 中可用的 reactive 属性后面。

您可以使用 reactiveSessionManager

SessionManager.
.default
.reactive
.request("your url goes here")
.responseString()
.map{ $0.value }
.startWithValues { print( $0 ?? "") }

或者如果您使用以下 Alamofire 中的快捷方式,您可以直接在请求上使用它

Alamofire.request("your url goes here")
.reactive
.responseString()
.map{ $0.value }
.startWithValyes { print( $0 ?? "" ) }

AlamofireReactiveExtensions 返回的每个 SignalProducer 都不能失败,因为 Alamofire 中的回调不返回错误。将 NoError 响应生成器转换为可以失败的生成器的转换留给用户处理。