Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dataSource and delegate methods with RxSwift

I'm trying to use UIPickerView with RxSwift. Is there a way to wrap the UIPickerView dataSource and delegate methods to be used with Observables? I'm trying to do something like

dataSequence
    .bindTo(pickerView.rx_itemsWithDataSource(dataSource))

I see there is a premade library for UITableview https://github.com/RxSwiftCommunity/RxDataSources but I'm wondering if there's an easy way to generalize this for other things that require dataSource and delegate using RxSwift.

like image 859
devgeek Avatar asked Apr 09 '16 23:04

devgeek


1 Answers

The basic RxCocoa pod which you should have imported with RxSwift in the podfile should already had this.

In case you didn't import that in your podfile, add

pod 'RxCocoa',    '~> 3.0'

Proceed then to bind the delegate like you would with a normal TableView. I didn't see any dataSource observable for UIPickerView though, so you should check that.

like image 156
Sơn Đỗ Đình Thy Avatar answered Nov 07 '22 04:11

Sơn Đỗ Đình Thy