【问题标题】:Combine in Playgrounds结合在游乐场
【发布时间】:2019-06-05 14:15:51
【问题描述】:

我正在检查 Apple 的新框架 Combine。我创建了一个 Playground,在 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)
        }
    }
}

但它失败并显示日志:

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

我做错了什么?

【问题讨论】:

  • 您必须运行 macOS 10.15。
  • 您可以在右侧的系统要求窗格中看到,需要macOS 10.15+
  • 这是一个公平的问题,它也不适用于 Catalina。
  • @MwcsMac 我有点困惑,为什么具有相同 macOS 10.15+ 要求的 SwiftUI 在 Xcode 11 的操场上工作,而 Combine 失败了。
  • 看起来 Xcode 11 beta 2 修复了这个问题。

标签: swift swift-playground combine


【解决方案1】:

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

如果您创建了一个 iOS Playground,那么您完全有可能在 Combine(或 Swift 编译器)中发现了一个错误。如果您愿意,可以通过Apple’s feedback site 举报。

【讨论】:

    【解决方案2】:

    Xcode 11 beta 的第一个版本没有使用 Combine,它已在发行说明中说明。

    您应该下载第二个 Xcode 11 beta (11M337n)

    【讨论】:

    • +1:此外,某些 beta 版本似乎也存在重大问题——例如beta 4 喜欢与 Combine @Published 属性一起崩溃...最好的选择是确保您始终处于最新的 beta 版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 2013-04-29
    • 2020-01-05
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多