CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

RxBrightFutures 1.0

RxBrightFutures 1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Junior B..



 
Depends on:
BrightFutures~> 5.1
RxSwift~> 3.0
 

  • By
  • Junior B.

RxBrightFutures

RxBrightFutures is a tiny wrapper around BrightFutures that allows transforming promises and futures into observables or subjects using a single function rx_observable or rx_subject.

Example

There’s a project as example in the repository, but the basic is shown in the following snipped:

let stringURL = "..."        
let url = NSURL(string: stringURL)!
let request = NSURLRequest(URL: url)
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)

let networkPromise = Promise<NSData, NSError>()

let task : NSURLSessionDataTask = session.dataTaskWithRequest(request) { (data, response, error) in

    if let e = error {
        networkPromise.tryFailure(e)
    } else {
        if let d = data {
            networkPromise.trySuccess(d)
        } else {
            networkPromise.tryFailure(NSError(domain: "Data error", code: -1, userInfo: nil))
        }
    }

}

networkPromise.future
    .flatMap() { value in
        return self.deserializeData(value)
    }
    .rx_observable()
    .subscribeNext() { json in
        self.toTextField.text = self.processData(json)
    }

task.resume()

Contributions

Contributions are welcomed in the develop repository. Any pull-request to the master branch will be rejected.

LICENSE

This project is released under MIT License.