iOS 응용 (swift)
[iOS - swift] throttle tap 커스텀
jake-kim
2021. 1. 14. 23:45
커스텀 방법
- RxCocoa를 사용할 때 button.rx.tap -> button.rx.throttleTap으로 사용
// 상수 정의
struct Constants {
static let throttleDurationMilliseconds = 500
}
// 커스텀 throttle 정의
extension Reactive where Base: UIButton {
public var throttleTap: ControlEvent<Void> {
return ControlEvent(events: tap.throttle(.milliseconds(Constants.throttleDurationMilliseconds), latest: false, scheduler: MainScheduler.instance))
}
}