gpt4 book ai didi

swift - 无法初始化 CloudKit 架构,因为协调器中没有任何商店配置为使用 CloudKit

转载 作者:行者123 更新时间:2023-12-05 09:34:39 35 4
gpt4 key购买 nike

我在尝试初始化 Cloudkit schema 时遇到此错误:

Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={NSLocalizedFailureReason=Couldn't initialize CloudKit schema because no stores in the coordinator are configured to use CloudKit: ()}

这是我的代码:

private lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentCloudKitContainer(name: self.objectModelName)

// Create a store description for a CloudKit-backed local store
let cloudStoreLocation = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("iCloud.sqlite")
let cloudStoreDescription = NSPersistentStoreDescription(url: cloudStoreLocation)
cloudStoreDescription.configuration = "iCloud"

// Set the container options on the cloud store
cloudStoreDescription.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.myname.app")

// Update the container's list of store descriptions
container.persistentStoreDescriptions = [
cloudStoreDescription
]

do {
try container.initializeCloudKitSchema()
} catch {
print(error)
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()

这是我的:project configuration

这是我的:data model schema

谁能帮我找出我做错了什么?

谢谢!

最佳答案

谁以后可能会遇到这个。我有同样的错误,问题与上面的示例代码相同。

我打电话

container.initializeCloudKitSchema()

打电话之前

container.loadPersistentStores

您需要在调用 container.loadPersistentStores 之后调用 container.initializeCloudKitSchema

关于swift - 无法初始化 CloudKit 架构,因为协调器中没有任何商店配置为使用 CloudKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66434038/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com