This was helpful, I wasn't able to find much this failure.
The formatting of your code block didn't work, lets see if I can paste your snippet and get the formatting better:
let bundle = Bundle.module
let modelURL = bundle.url(forResource: "ModelName", withExtension: ".momd")!
let model = NSManagedObjectModel(contentsOf: modelURL)!
let container = NSPersistentCloudKitContainer(name: "ModelName", managedObjectModel: model)
My situation was a little different, a test case target that wasn't finding the model for some reason, and Bundle.main wasn't right, that was some test runner process embedded in Xcode.app, . To find the right one I have to dive into allBundles with let bundle = Bundle.allBundles.first(where: { $0.bundleURL.pathExtension == "xctest" }):
guard let bundle = Bundle.allBundles.first(where: { $0.bundleURL.pathExtension == "xctest" }) else {
fatalError("can't find test bundle containing model")
}
guard let modelURL = bundle.url(forResource: "Storage", withExtension: ".momd") else {
fatalError("can't find model")
}
guard let model = NSManagedObjectModel(contentsOf: modelURL) else {
fatalError("can't create model")
}
let container = NSPersistentCloudKitContainer(name: "ModelName", managedObjectModel: model)
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: