Then in my controller i define the data stack like this:
let coreData = DATAStack(modelName: "Test", storeType: .sqLite)
Later I'd like to do a count on the Product entity like this:
do {
let productCount = try coreData.viewContext.count(for: Product.fetchRequest())
debugPrint("product Count in coredata: \(productCount)")
}
catch let e {
debugPrint(e.localizedDescription)
}
That works as expected!
Now I'd like to do some kind of archive with the exact same model. So what I did is to just create another instance with the same model like this:
After that the productCount will not work anymore and the app crashes with the following message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '_countWithNoChangesForRequest:error: A fetch request must have an entity.
Here is the whole code to reproduce this behaviour:
import UIKit
import DATAStack
class ViewController: UIViewController {
let coreData = DATAStack(modelName: "Test", storeType: .sqLite)
let archive = DATAStack(modelName: "Test", bundle: Bundle.main, storeType: .sqLite, storeName: "Test-Archive", containerURL: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!)
override func viewDidLoad() {
super.viewDidLoad()
debugPrint("coreData located at: \(coreData.viewContext.persistentStoreCoordinator!.persistentStores.first!.url!.absoluteString)")
debugPrint("archive located at: \(archive.viewContext.persistentStoreCoordinator!.persistentStores.first!.url!.absoluteString)")
do {
let productCount = try coreData.viewContext.count(for: Product.fetchRequest())
debugPrint("product Count in coredata: \(productCount)")
}
catch let e {
debugPrint(e.localizedDescription)
}
}
}
Can anyone help me with this one? How can I approach this?
Thx
Hi I've got the following model (for example)
Then in my controller i define the data stack like this:
Later I'd like to do a count on the Product entity like this:
That works as expected!
Now I'd like to do some kind of archive with the exact same model. So what I did is to just create another instance with the same model like this:
After that the productCount will not work anymore and the app crashes with the following message:
Here is the whole code to reproduce this behaviour:
Can anyone help me with this one? How can I approach this? Thx