繁体   English   中英

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

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

无法在 rxswift 中为去抖动设置 Rxtimeinterval。 我的代码如下。 我收到此错误消息“无法将 '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 }

错误信息:

“无法将‘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 }

改变这一行:

.debounce(0.5, scheduler: MainScheduler.instance)

到这一行:

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

“无法将‘Double’类型的值转换为预期的参数类型‘RxTimeInterval’(又名‘DispatchTimeInterval’)”

我遇到了同样的错误,我只是添加了这个:

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

而不是这个.debounce(0.5, scheduler: MainScheduler.instance)


只要确保以milliseconds(<value>)的值milliseconds(<value>)是一个 int

暂无
暂无

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

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