RetroObjective enable you to receive delegate events by subscribed handler.
This is swift 5 and later generic version of DelegateProxy by DelegateProxy
- Swift 5 / Xcode 9
- OS X 10.12 or later
- iOS 10.0 or later
- watchOS 3.0 or later
- tvOS 10.0 or later
Add the following to your Podfile:
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'RetroObjective', :git => 'https://github.com/amine2233/RetroObjective.git'
end
$ pod install
Add the following to your Cartfile:
github "amine2233/RetroObjective"
$ carthage update
Create RetroObjective
inherited class.
final class ScrollViewDelegateProxy: RetroObjective, UIScrollViewDelegate, RetroObjectiveType {
func resetDelegateProxy(owner: UIScrollView) {
owner.delegate = self
}
}
It can be useful to implements extension.
extension UIScrollView {
var delegateProxy: ScrollViewDelegateProxy {
return .proxy(for: self)
}
}
You can receive delegate events as following.
scrollView.delegateProxy
.receive(#selector(UIScrollViewDelegate.scrollViewDidScroll(_:))) { args in
guard let scrollView: UIScrollView = args.value(at: 0) else { return }
print(scrollView.contentOffset)
}
You can add a new publisher on UIScrollView
extension UISCrollView {
var value: AnyPublisher<UISCrollView, Never> {
Publishers.proxyDelegate(delegateProxy, selector: #selector(UIScrollViewDelegate.scrollViewDidScroll(_:)))
.compactMap { $0.value(at: 0) as? UISCrollView }
.eraseToAnyPublisher()
}
}
Welcome to fork and submit pull requests!!
Before submitting pull request, please ensure you have passed the included tests. If your pull request including new function, please write test cases for it.
DelegateProxy is released under the MIT License.