在 Swift Combine 中使用 Publishers.debounce() 的正确语法是什么?

ken*_*nyc 9 swift swift5 combine

在 Apple 的 2019 年 WWDC 视频中Swift Combine in Practice,他们演示了使用debounce发布者来减慢消息速度。

return $username
  .debounce(for: 0.5, scheduler: RunLoop.main)
  .removeDuplicates()
  .eraseToAnyPublisher()
Run Code Online (Sandbox Code Playgroud)

但是,每当我尝试以类似的方式使用它时,都会出现以下错误:

无法使用类型为“(for:Double,调度程序:RunLoop)”的参数列表调用“debounce”

debounce()签名是:

public func debounce<S>(for dueTime: S.SchedulerTimeType.Stride, 
                          scheduler: S,
                            options: S.SchedulerOptions? = nil) -> 
                                    Publishers.Debounce<Self, S> where S : Scheduler
Run Code Online (Sandbox Code Playgroud)

SchedulerTimeType.Stride 似乎可以用数字初始化,但它对我不起作用,或者我对 Swift 泛型缺乏经验。

调用它的正确方法是什么?

编辑

重复这个问题...

目前,搜索诸如“组合”之类的通用词相当具有挑战性......

macOS 10.15,Xcode 11

cds*_*per 15

记录的 debounce<S>操作者接受型S.SchedulerTimeType.Stride,看起来是这样的:

let sub = NotificationCenter.default
    .publisher(for: NSControl.textDidChangeNotification, object: filterField)
    .debounce(for: .milliseconds(500), scheduler: RunLoop.main)
    .subscribe(on: RunLoop.main)
    .assign(to:\MyViewModel.filterString, on: myViewModel)
Run Code Online (Sandbox Code Playgroud)