如何在RxSwift中为反跳设置RxTimeInterval?

Bik*_*jan 4 xcode ios swift rx-swift

无法为rxswift中的去抖动设置Rxtimeinterval。我的代码如下。我收到此错误消息“无法将类型'Double'的值转换为预期的参数类型'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 }
Run Code Online (Sandbox Code Playgroud)

错误信息:

“无法将类型为'Double'的值转换为预期的参数类型'RxTimeInterval'(aka'DispatchTimeInterval')”

iel*_*ani 10

更改这一行:

.debounce(0.5, scheduler: MainScheduler.instance)
Run Code Online (Sandbox Code Playgroud)

到这一行:

.debounce(RxTimeInterval.milliseconds(500), scheduler: MainScheduler.instance)
Run Code Online (Sandbox Code Playgroud)


iWh*_*Buy 7

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 }
Run Code Online (Sandbox Code Playgroud)