我在 SwiftUI 中编写了一个 iOS 应用程序(使用 Xcode 12 中的 SwiftUI 生命周期),该应用程序使用我的 CloudKit 容器的公共(public)数据库以及以下代码行:
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 容器的公共(public)数据库。但是,当我尝试在 Mac 应用程序的 AppDelegate.swift
文件中构建以下代码时,Xcode 给我一个错误,指出它无法找到“databaseScope”成员。该成员变量仅适用于 iOS 应用程序吗?如果是这种情况,如何在 macOS 应用中访问 Cloudkit 容器的公共(public)数据库?
最佳答案
尝试将“导入 CloudKit”添加到文件顶部。
为我解决了这个问题。
关于core-data - 使用公共(public) CloudKit 数据库 (NSPersistentCloudkitContainer) - macOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64520373/