junmo-kim / RxToBolts

Objective-C Bolts wrapper for one time event RxSwift traits

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RxToBolts

Objective-C Bolts wrapper for RxSwift one time event traits

Build Status

If you want to introduce RxSwift but hesitated from tons of legacy Objective-C classes, this can help.

Get started

  1. In Podfile add this and install
pod 'RxToBolts'
  1. Write your Rx code in Swift
@objc class Service {
    func getStatus() -> Single<Status> {
        return Single<Status>.create { observer -> Disposable in
            [...]
        }
    }
}
  1. Add wrapper method without any efforts
extension Service {
    @objc func objc_getStatus() -> BFTask<Status> {
        return getStatus().toBoltsTask()
    }
}
  1. Use it on Objective-C
- (void)didTapLoadStatus {
    [[Service objc_getStatus] continueWithBlock:^id(BFTask *task) {
        if (task.isCancelled) {
            // get status was cancelled.
        } else if (task.error) {
            // get status failed.
        } else {
            Status *status = task.result;
            NSLog(@"Status: %@", status.text);
        }
        return nil;
    }];
}

🎉

About

Objective-C Bolts wrapper for one time event RxSwift traits

License:MIT License


Languages

Language:Swift 72.4%Language:Ruby 26.1%Language:Objective-C 1.5%