iOS Swift: 'NotificationCenter' 类型的值没有成员 'publisher'

iOS Swift: Value of type 'NotificationCenter' has no member 'publisher'

我正在尝试将新的 Combine 框架与 Notification Center 一起使用,正如 Apple 在此视频中所解释的那样: https://developer.apple.com/videos/play/wwdc2019/721/

您可以在幻灯片 21 中找到它。

我的项目好像没有读取Combine框架的api。

import Combine
import Foundation

let trickNamePublisher = NotificationCenter.default.publisher(for: .newTrickDownloaded)

我收到这个错误:

类型 'NotificationCenter' 的值没有成员 'publisher'

显然在 Xcode 11 beta 中有这个已知问题:

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)

link: https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_release_notes/

事实上,他们在演示期间没有使用 Xcode,只是在幻灯片上编写代码

此问题已通过 Xcode 11 beta 2 修复。来自 Xcode 11 Beta 2 Release Notes:

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)