gpt4 book ai didi

swift - 如何使用 combine Publisher 更改线程?

转载 作者:可可西里 更新时间:2023-11-01 00:54:05 25 4
gpt4 key购买 nike

我正在使用 Combine 和 SwiftUI 来做一些异步的事情,关键是我不知道如何在主线程中接收异步操作的响应。 apple doc说它可以用于 RunLoop.main,但目前在 Swift 5.0 中它不是一个调度器。那么对此有什么想法吗?

我尝试按照 apple doc 使用,但没有成功。

anyPublisher
.receiveOn(on: RunLoop.main)

最佳答案

Combine - 在撰写本文时 - 未完全集成到 Foundation 中。

根据 Xcode 11 Beta Release Notes :

The Foundation integration for the Combine framework is unavailable. The following Foundation and Grand Central Dispatch integrations with Combine are unavailable: KeyValueObserving, NotificationCenter, RunLoop, OperationQueue, Timer, URLSession, DispatchQueue, JSONEncoder, JSONDecoder, PropertyListEncoder, PropertyListDecoder, and the @Published property wrapper. (51241500)


根据最新的 Xcode 11 beta (2),此问题已得到修复,因此请期待您的代码能够正常工作。

The Foundation integration for the Combine framework is now available. The following Foundation and Grand Central Dispatch integrations with Combine are available: KeyValueObserving, NotificationCenter, RunLoop, OperationQueue, Timer, URLSession, DispatchQueue, JSONEncoder, JSONDecoder, PropertyListEncoder, PropertyListDecoder, and the @Published property wrapper. (51241500)

感谢@Martin R 和@silicon_valley 的 update .

关于swift - 如何使用 combine Publisher 更改线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56551108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com