Objective-C Bolts wrapper for RxSwift one time event traits
If you want to introduce RxSwift but hesitated from tons of legacy Objective-C classes, this can help.
- In Podfile add this and install
pod 'RxToBolts'
- Write your Rx code in Swift
@objc class Service {
func getStatus() -> Single<Status> {
return Single<Status>.create { observer -> Disposable in
[...]
}
}
}
- Add wrapper method without any efforts
extension Service {
@objc func objc_getStatus() -> BFTask<Status> {
return getStatus().toBoltsTask()
}
}
- 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;
}];
}
🎉