如何使用 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/