Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSPersistentContainer/核心数据/只读存储_Ios_Core Data - Fatal编程技术网

Ios NSPersistentContainer/核心数据/只读存储

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

我刚刚在核心数据上建立了一个只读数据存储。它的工作,但编译器有一个抱怨,我想知道如何解决这个问题

这里的相关代码是我在Xcode修改后自动生成的模板

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。