[RxSwift] Delegate Proxy

Using Swift’s Delegate Methods with Rx

Jay Lee
May 6, 2022

If you look into the folder named ‘Common’ at [Pods>RxCocoa>]you can find two swift files, DelegateProxy.swift and DelegateProxyType.swift.

DelegateProxy is a bridge that links RxSwift and Swift’s Delegate methods, which helps you to use delegate methods, like UITableViewDelegate and MKMapViewDelegate, in RxSwift/RxCocoa.

explanation inside the DelegateProxyType.swift file

Normally we would use MapKit Delegate methods like below

However, with DelegateProxy, we could use methods like the below somehow

In order to achieve that
1. make UICollectionViewDelegateProxy class
2. inherit from the DelegateProxy class

class (name)DelegateProxy
: DelegateProxy<
(a class you’ll be using on), (delegate)>
, DelegateProxyType
,
(delegate) {

}

And then make methods you’ll be using in extension closure

Then that’s it. All you have to do is just listen to those changes like below :)

--

--