DispatchQueue 在 Swift 中不工作的问题
Issue with the DispatchQueue not working in 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
那个教程有一个问题,就是链$city.…
创建的订阅者没有保存在任何地方,所以它立即被取消和释放。将其保存在 属性 中或使用 .store(in: &mySubscribers)
.
将其添加到 Set<AnyCancellable>
属性
我被这个问题困住了,尝试了各种方法,但没有成功。下面的代码几天前就可以使用了。但是,它现在不起作用。我尝试使用 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
那个教程有一个问题,就是链$city.…
创建的订阅者没有保存在任何地方,所以它立即被取消和释放。将其保存在 属性 中或使用 .store(in: &mySubscribers)
.
Set<AnyCancellable>
属性