Want to use ReactiveSwift with Alamofire? AlamofireReactiveExtensions has you covered. It provides a list of extensions that bridge Alamofire's callbacks with ReactiveSwift's SignalProducers. You can even easily apply ReactiveSwift's operators to your responses, combine multiple requests or execute requests consecutively.'
The project currently provides extensions for:
SessionManager
DataRequest
DownloadRequest
UploadRequest
For requests AlamofireReactiveExtensions
provides the following functions:
request(queue:)
request(queue:,responseSerializer)
responseData(queue:)
responseString(queue:, encoding:)
responseJSON(queue:s options:)
responsePropertyList(queue:, options:)
SessionManager supports the following functions:
request(_:, method:, parameters:, encoding:, headers:)
request(_:)
download(_:, method:, parameters:, encoding:, headers:, to)
download(_:, to:)
download(resumingWith:, to:)
upload(_:, to:, method:, headers:)
upload(_:, with:)
upload(_:, to:, method:, headers: )
upload(_:, with:)
upload(_:, to:, method:, headers:)
stream(withHostName:, port:)
AlamofireReactiveExtensions
is available through CocoaPods
pod 'AlamofireReactiveExtensions'
ReactiveSwift
extensions are located behind the reactive
property that is available in SessionManager
, DataRequest
, DownloadRequest
, UploadRequest
.
You can use reactive
with a SessionManager
SessionManager.
.default
.reactive
.request("your url goes here")
.responseString()
.map{ $0.value }
.startWithValues { print( $0 ?? "") }
or if you use the shortcuts available in Alamofire
you can use it immediately on a request:
Alamofire.request("your url goes here")
.reactive
.responseString()
.map{ $0.value }
.startWithValyes { print( $0 ?? "" ) }
Each SignalProducer
returned from AlamofireReactiveExtensions
cannot fail since the callbacks in Alamofire
do not return errors. The convertion of the NoError
response producer to a producer that can fail is left to the user.