I have a requirement for two different CoreData database stores, depending on which mode my application is running in. It will only need to be switched when the application first runs.
Ideally this would get setup with the persistentContainer:
lazy var persistentContainer: NSPersistentContainer =
{
let container = NSPersistentContainer(name: "myApp")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError?
{
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
}
I basically just need to find a command like:
if mode == 1
{
storeName = "MyStore1.sqlite"
}
else
{
storeName = "MyStore2.sqlite"
}
container.useStore(storeName)