[RxSwift] Delegate Proxy

Using Swift’s Delegate Methods with Rx

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 :)



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store