I have written this app in Swift 5 and is already LIVE in App Store.
Now, I just want to add a new single boolean attribute to one existing entity in coredata.
For this purpose, I followed steps:
- Added version to Project.xcdatamodeld (It auto created Project 2.xcdatamodel file inside it)
- Set this version as default
- Add one attribute to entity in this new version file.
- Added properties shouldMigrateStoreAutomatically and shouldInferMappingModelAutomatically to NSPersistentContainer in AppDelegate class.
Issue:
While in app, I am successfully able to save data in coredata and retrieve from coredata in any ViewController but, if app opens from start, it cannot find previous file and recreates coredata file.
Whenever I open app, it shows error in xCode console:
Connecting to sqlite database file at "/dev/null"
AppDelegate code:
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Project")
let description = NSPersistentStoreDescription()
description.shouldMigrateStoreAutomatically = true
description.shouldInferMappingModelAutomatically = true
container.persistentStoreDescriptions=[description]
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container }()
Tutorial I followed: Medium