Originally created by @siempay on GitHub (Sep 19, 2018).
I have a framework where I setup my model layer and there I have "Model.xcdatamodeld" file where my model graph is, but following the tuto here, I could not addStorage successfully
and keep getting this: "Could not find \"Model.momd\" from the bundle \"com.utopie.myapp\". Other model files in bundle: 0 item(s) []"
as I understood : I should do just try CoreStore.addStorageAndWait() inside the framework where my file is! am I right ?
Originally created by @siempay on GitHub (Sep 19, 2018).
I have a framework where I setup my model layer and there I have `"Model.xcdatamodeld"` file where my model graph is, but following the tuto here, I could not addStorage successfully
and keep getting this: `"Could not find \"Model.momd\" from the bundle \"com.utopie.myapp\". Other model files in bundle: 0 item(s) []"
`
as I understood : I should do just `try CoreStore.addStorageAndWait()` inside the framework where my file is! am I right ?
adam
added the question label 2025-12-29 18:24:36 +01:00
I used all simples from your documentation: CoreStore.defaultStack = DataStack( xcodeModelName: "myModel")
but I could not connect to my model file.
This is what Im already using to load persistant store
/// context public func getContext() -> NSManagedObjectContext{ return self.persistentContainer.viewContext }
// MARK: - Core Data stack
public lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let modelURL = Bundle(for: type(of: self)).url(forResource: "Model", withExtension: "momd")!
let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL)
let container = NSPersistentContainer(name: "ModelTDLPV", managedObjectModel: managedObjectModel!)
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()`
@siempay commented on GitHub (Sep 24, 2018):
I used all simples from your documentation:
`CoreStore.defaultStack = DataStack(
xcodeModelName: "myModel")`
but I could not connect to my model file.
**This is what Im already using to load persistant store**
`/// context
public func getContext() -> NSManagedObjectContext{
return self.persistentContainer.viewContext
}`
// MARK: - Core Data stack
public lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
application to it. This property is optional since there are legitimate
error conditions that could cause the creation of the store to fail.
*/
let modelURL = Bundle(for: type(of: self)).url(forResource: "Model", withExtension: "momd")!
let managedObjectModel = NSManagedObjectModel(contentsOf: modelURL)
let container = NSPersistentContainer(name: "ModelTDLPV", managedObjectModel: managedObjectModel!)
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()`
@JohnEstropia commented on GitHub (Sep 25, 2018):
You mention you are using a framework, so your model's source `Bundle` is not `Bundle.main` which CoreStore uses as default. Please try:
```swift
CoreStore.defaultStack = DataStack(xcodeModelName: "Model", bundle: Bundle(for: type(of: self)))
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @siempay on GitHub (Sep 19, 2018).
I have a framework where I setup my model layer and there I have
"Model.xcdatamodeld"file where my model graph is, but following the tuto here, I could not addStorage successfullyand keep getting this:
"Could not find \"Model.momd\" from the bundle \"com.utopie.myapp\". Other model files in bundle: 0 item(s) []"as I understood : I should do just
try CoreStore.addStorageAndWait()inside the framework where my file is! am I right ?@JohnEstropia commented on GitHub (Sep 20, 2018):
Can you show the exact code you are calling?
@siempay commented on GitHub (Sep 24, 2018):
I used all simples from your documentation:
CoreStore.defaultStack = DataStack( xcodeModelName: "myModel")but I could not connect to my model file.
This is what Im already using to load persistant store
/// context public func getContext() -> NSManagedObjectContext{ return self.persistentContainer.viewContext }@JohnEstropia commented on GitHub (Sep 25, 2018):
You mention you are using a framework, so your model's source
Bundleis notBundle.mainwhich CoreStore uses as default. Please try: