Search code examples
iosswift3reactivekit

Passing a proxy data source in Bond5 tableview/collectionview binding


With Bond 4.x it was possible to pass my custom data source when binding a tableview to an ObservableArray in order to implement custom invocations of UICollectionViewDataSource methods (e.g. viewForSupplementaryElementOfKind) like this:

viewModel.dataSource.bindTo(collectionView, proxyDataSource: HeaderViewCreator()) { indexPath, dataSource, tableView

This is gone now in Bond5 as trying to use the proxyDataSource parameter causes a compiler error expecting a different argument label in the call.

Unfortunately I could not find a proper section in the migration guide and also I had a hard time understanding the documentation in that regard. BNDTableViewProxyDataSource and friends seem to be gone completely from the codebase.

Thanks for any kind of help!


Solution

  • UITableView and UICollectionView now have properties bnd_delegate and bnd_dataSource of type ProtocolProxy. That type has a property forwardTo that you can set to receive delegate or data source callbacks that are not used by ProtocolProxy (i.e. Bond).

    For example:

    class MyViewController: UITableViewDelegate {
    
      var tableView: UITableView
    
      func viewDidLoad() {
        super.viewDidLoad()
        tableView.bnd_delegate.forwardTo = self
      }
    }