首页 > 解决方案 > DispatchQueue 在 Swift 中不起作用的问题

问题描述

我被这个问题困扰并尝试了各种方法,但没有运气。下面的代码用于几天前工作。但是,它现在不起作用。我尝试使用 Xcode 版本 11.1 并像魅力一样工作。有人可以让我知道可能是什么原因或解决方法吗?

问题是每当我输入一个键时,它都不会使用调度队列触发相应的方法。

当前的 Swift 版本:11.3

Code snippet:

 init(
    weatherFetcher: WeatherFetchable,
    scheduler: DispatchQueue = DispatchQueue(label: "WeatherViewModel")
  ) {
    self.weatherFetcher = weatherFetcher
    _ = $city
      .dropFirst(1)
      .debounce(for: .seconds(0.5), scheduler: DispatchQueue.global())
      .sink(receiveValue: fetchWeather(forCity:))
  }

参考代码: https ://www.raywenderlich.com/4161005-mvvm-with-combine-tutorial-for-ios

标签: iosswiftxcodecombine

解决方案



推荐阅读