【发布时间】:2021-02-07 17:18:30
【问题描述】:
我在 SwiftUI 中编写了一个 iOS 应用程序(使用 Xcode 12 中的 SwiftUI 生命周期),它使用我的 CloudKit 容器的公共数据库和以下代码行:
let container = NSPersistentCloudKitContainer(name: "my_ios_container_name")
guard let description = container.persistentStoreDescriptions.first else {
print("Can't set description")
fatalError("Error")
}
description.cloudKitContainerOptions?.databaseScope = .public
我正在用 SwiftUI 编写一个 macOS 应用程序,它可以访问同一个 CloudKit 容器的公共数据库。但是当我尝试在我的 mac 应用程序的 AppDelegate.swift 文件中构建下面的代码时,Xcode 给我一个错误,说它无法找到“databaseScope”成员。此成员变量是否仅适用于 iOS 应用程序?如果是这种情况,如何在 macOS 应用中访问 Cloudkit 容器的公共数据库?
【问题讨论】:
-
是的,它仅在 iOS 上可用,所以如果您想设置该描述选项,只需将其包装到仅适用于 iOS 的可用性条件中。
-
谢谢!我的 macOS 应用程序的功能依赖于访问公共数据库,所以我唯一的选择是等到 Apple 添加这个吗?
-
我猜您可以从您的 macOS 应用程序访问公共数据库,而无需使用 NSPersistentCloudKitContainer。您可以从 CKContainer.default.publicCloudDatabase 中获取 CKRecords。
标签: core-data swiftui cloudkit xcode12