16

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')"

iWheelBuy
  • 5,470
  • 2
  • 37
  • 71
Bikash Maharjan
  • 163
  • 1
  • 1
  • 4

3 Answers3

34
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 }
iWheelBuy
  • 5,470
  • 2
  • 37
  • 71
10

Change this line:

.debounce(0.5, scheduler: MainScheduler.instance)

To this line:

.debounce(RxTimeInterval.milliseconds(500), scheduler: MainScheduler.instance)
PhillipJacobs
  • 2,337
  • 1
  • 16
  • 32
ielyamani
  • 17,807
  • 10
  • 55
  • 90
1

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

I got the same error and i just added this:

.debounce(RxTimeInterval.milliseconds(500), scheduler: MainScheduler.instance)

instead of this .debounce(0.5, scheduler: MainScheduler.instance)


Just make sure your value in milliseconds(<value>) is an int