core-data - 使用公共 CloudKit 数据库 (NSPersistentCloudkitContainer) - macOS
问题描述
我在 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 编写一个访问同一个 CloudKit 容器的公共数据库的 macOS 应用程序。但是当我尝试在我的 mac 应用程序AppDelegate.swift
文件中构建下面的代码时,Xcode 给我一个错误,说它无法找到“databaseScope”成员。此成员变量是否仅适用于 iOS 应用程序?如果是这种情况,您如何在 macOS 应用程序中访问 Cloudkit 容器的公共数据库?
解决方案
尝试将“import CloudKit”添加到文件顶部。
为我解决了这个问题。
推荐阅读
- assembly - 程序查找单词出现的运行时异常
- python - 向量化双重求和的 Pythonic 方法
- ruby-on-rails - 期望响应具有成功状态代码 (2xx) 但它是 401
- python - QLineEdit 设置标题大小写
- html - mwlDraggable (Drag & Drop) - 移动的最小长度
- powerbi - Power BI 非活动关系
- python - 需要代码方法/建议 [python,django,html]
- c++ - 链表迭代器实现 C++
- java - 无法正确构建运行条件正确的 do while 循环
- c++ - 如何使变量始终等于某些计算的结果?