我在尝试初始化 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
}()
这是我的:项目配置 https://i.stack.imgur.com/Hf3UB.png
这是我的:数据模型架构 https://i.stack.imgur.com/NI3d8.png
你能帮我找出我做错了什么吗?
Thanks!
谁以后可能会遇到这个。我遇到了同样的错误,问题与上面的示例代码相同。
I called
container.initializeCloudKitSchema()
打电话之前
container.loadPersistentStores
您需要在调用container.loadPersistentStores后调用container.initializeCloudKitSchema
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)