Ios NSPersistentContainer/核心数据/只读存储
我刚刚在核心数据上建立了一个只读数据存储。它的工作,但编译器有一个抱怨,我想知道如何解决这个问题 这里的相关代码是我在Xcode修改后自动生成的模板Ios NSPersistentContainer/核心数据/只读存储,ios,core-data,Ios,Core Data,我刚刚在核心数据上建立了一个只读数据存储。它的工作,但编译器有一个抱怨,我想知道如何解决这个问题 这里的相关代码是我在Xcode修改后自动生成的模板 lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "MyApp") let appName: String = "MyApp", storeUrl = Bundle.main
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "MyApp")
let appName: String = "MyApp",
storeUrl = Bundle.main.url(forResource: appName, withExtension: "sqlite")
var persistentStoreDescriptions: NSPersistentStoreDescription
let description = NSPersistentStoreDescription()
description.shouldInferMappingModelAutomatically = true
description.shouldMigrateStoreAutomatically = true
description.url = storeUrl
container.persistentStoreDescriptions = [description]
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
下面是我从编译器得到的信息:
[error] CoreData: error: Attempt to add read-only file at path ...../MyApp.app/MyApp.sqlite read/write. Adding it read-only instead. This will be a hard error in the future; you must specify the NSReadOnlyPersistentStoreOption.
如何设置此选项以使编译器满意?在说明中设置此选项
description.setOption(NSNumber(value: true), forKey: NSReadOnlyPersistentStoreOption)
顺便说一下:变量
persistentstorescriptions
未使用。在描述中设置选项
description.setOption(NSNumber(value: true), forKey: NSReadOnlyPersistentStoreOption)
顺便说一下:变量
persistentStoreDescriptions
未使用。是的,就是这样。谢谢。persistentStoreDescriptions是的,就是这样。谢谢。persistentStoreDescriptions为True。