She*_*tif 5 core-data core-data-migration ios swift
我用 Swift 5 编写了这个应用程序,并且已经在 App Store 中上线。
现在,我只想向一个现有实体添加一个新的单个布尔属性。
为此,我遵循了以下步骤:
问题:
在应用程序中,我能够成功地将数据保存在 coredata 中并从任何 ViewController 中的 coredata 中检索数据,但是,如果应用程序从头打开,它无法找到以前的文件并重新创建 coredata 文件。
每当我打开应用程序时,它都会在 xCode 控制台中显示错误:
Connecting to sqlite database file at "/dev/null"
Run Code Online (Sandbox Code Playgroud)
应用程序委托代码:
// 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 }()
Run Code Online (Sandbox Code Playgroud)
我遵循的教程: 中
该错误消息可能表明应用程序不知道在哪里查找或保存数据库文件。该短语"/dev/null"表示在内存存储中。
尝试使用
let description = NSPersistentStoreDescription(url: <- File url to the main database file ->)
Run Code Online (Sandbox Code Playgroud)
而不是当前的实例化。
| 归档时间: |
|
| 查看次数: |
1198 次 |
| 最近记录: |