如何使用 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 {
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)