Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set RxTimeInterval for debounce in RxSwift?

Unable to set Rxtimeinterval for debounce in rxswift. My code is below. I got this error message "Cannot convert value of type 'Double' to expected argument type 'RxTimeInterval' (aka 'DispatchTimeInterval')"

searchBar
    .rx.text // Observable property thanks to RxCocoa
    .orEmpty // Make it non-optional
    .debounce(0.5, scheduler: MainScheduler.instance) // Wait 0.5 for changes.
    .distinctUntilChanged() // If they didn't occur, check if the new value is the same as old.
    .filter { !$0.isEmpty }

error message:

"Cannot convert value of type 'Double' to expected argument type 'RxTimeInterval' (aka 'DispatchTimeInterval')"

like image 779
Bikash Maharjan Avatar asked Jun 08 '19 13:06

Bikash Maharjan


2 Answers

searchBar
    .rx.text // Observable property thanks to RxCocoa
    .orEmpty // Make it non-optional
    .debounce(.milliseconds(500), scheduler: MainScheduler.instance) // Wait 0.5 for changes.
    .distinctUntilChanged() // If they didn't occur, check if the new value is the same as old.
    .filter { !$0.isEmpty }
like image 66
iWheelBuy Avatar answered Sep 22 '22 07:09

iWheelBuy


Change this line:

.debounce(0.5, scheduler: MainScheduler.instance)

To this line:

.debounce(RxTimeInterval.milliseconds(500), scheduler: MainScheduler.instance)
like image 43
ielyamani Avatar answered Sep 26 '22 07:09

ielyamani