簡體   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