简体   繁体   English

如何在 RxSwift 中设置 RxTimeInterval 以进行去抖动?

[英]How to set RxTimeInterval for debounce in RxSwift?

Unable to set Rxtimeinterval for debounce in rxswift.无法在 rxswift 中为去抖动设置 Rxtimeinterval。 My code is below.我的代码如下。 I got this error message "Cannot convert value of type 'Double' to expected argument type 'RxTimeInterval' (aka 'DispatchTimeInterval')"我收到此错误消息“无法将 'Double' 类型的值转换为预期的参数类型 'RxTimeInterval'(又名 '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')" “无法将‘Double’类型的值转换为预期的参数类型‘RxTimeInterval’(又名‘DispatchTimeInterval’)”

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 }

Change this line:改变这一行:

.debounce(0.5, scheduler: MainScheduler.instance)

To this line:到这一行:

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

"Cannot convert value of type 'Double' to expected argument type 'RxTimeInterval' (aka 'DispatchTimeInterval')" “无法将‘Double’类型的值转换为预期的参数类型‘RxTimeInterval’(又名‘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)而不是这个.debounce(0.5, scheduler: MainScheduler.instance)


Just make sure your value in milliseconds(<value>) is an int只要确保以milliseconds(<value>)的值milliseconds(<value>)是一个 int

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM