ios - 如何使用选项字典关闭 Swift 中的核心数据预写日志记录?

标签 ios core-data swift

如何使用 Apple 的新编程语言 Swift 关闭 Core Data 中的 SQLite 预写日志记录 (WAL)?

在 ObjC 中,我曾经在选项字典中传入键值对 @"journal_mode": @"DELETE":

[storeCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                               configuration:nil
                                         URL:[self databaseURL]
                                     options:@{NSMigratePersistentStoresAutomaticallyOption: @YES,
                                           NSInferMappingModelAutomaticallyOption: @YES,
                                           @"journal_mode": @"DELETE"}
                                       error:&error]

但在 Swift 中,NSDictionary 中只允许使用相同的类型,因此混合 BOOL(映射到 NSNumber)和 NSString 是不可能的。

有什么想法吗?

最佳答案

这些答案很接近,但实际上都不适合我。以下确实有效。该选项必须与 NSSQLitePragmasOption 一样。

var options = Dictionary<NSObject, AnyObject>()
options[NSMigratePersistentStoresAutomaticallyOption] = true
options[NSInferMappingModelAutomaticallyOption] = true
options[NSSQLitePragmasOption] = ["journal_mode" : "DELETE"]
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options, error: &error) == nil {
    ...
}

关于ios - 如何使用选项字典关闭 Swift 中的核心数据预写日志记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25667447/

相关文章:

swift - 在现有部分创建 PushRow 并在运行时传递值

ios - 当应用程序一段时间不使用时调暗显示

ios - 无法运行有关 PJSip 的 iPhone 模拟器

objective-c - NSPredicate 根据父实体的属性搜索子实体实例

iphone - 使用 coredata 准备应用发布

ios - 如何使用普通按钮而不是条形按钮项目

ios - 限制 Core Data 存储大小的最佳方法是什么?

ios - 从核心数据中一对多关系中的实体获取数据

ios - 标签类型的导出数组

ios - 从上下文中分离(断开)核心数据实体