[英]Issue with the DispatchQueue not working in Swift
我被這個問題困住了,嘗試了各種方法,但沒有運氣。 下面的代碼用於幾天前的工作。 但是,它現在不起作用。 我嘗試使用 Xcode 11.1 版,效果很好。 有人可以讓我知道可能是什么原因或解決方法嗎?
問題是每當我輸入一個鍵時,它不會使用 dispatchqueue 觸發相應的方法。
當前 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.…
創建的訂閱者沒有保存在任何地方,所以它立即被取消和釋放。 將其保存在屬性中或使用Set<AnyCancellable>
.store(in: &mySubscribers)
將其添加到Set<AnyCancellable>
屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.