结合在操场上

Art*_*kov 6 swift swift-playground combine

我正在检查Apple的新框架Combine。我创建了一个游乐场,并在macOS Mojave 10.14.5和Xcode 11.0 beta(11M336w)中运行了它。

这是我的代码:

import Combine

struct Article: Identifiable {

    var id: Int
    var title: String
}

final class Data: BindableObject {

    let didChange = PassthroughSubject<Data, Never>()

    var showFavouriteOnly = false {
        didSet {
            didChange.send(self)
        }
    }
    var articles: [Article] = [.init(id: 1, title: "WWDC 2018"),
                               .init(id: 2, title: "WWDC 2019")] {
        didSet {
            didChange.send(self)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是它失败并显示日志:

错误:无法查找符号:Combine.PassthroughSubject.send(A)->()

我究竟做错了什么?

rob*_*off 2

如果您创建了 iOS Playground,那么Combine即使您\xe2\x80\x99 在 macOS 10.14 上运行 Xcode 11 或更高版本,也应该可以工作。如果您创建了 macOS Playground,Combine则仅当您在 macOS 10.15 (Catalina) 或更高版本上运行 Xcode 11 或更高版本时才有效。

\n\n

如果您创建了一个 iOS Playground,那么您完全有可能在 Combine(或 Swift 编译器)中发现了错误。如果您愿意,您可以在Apple\xe2\x80\x99s 反馈网站上报告该问题。

\n