Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off Core Data Write-Ahead logging in Swift using options dictionary?

How do I turn off the SQLite Write ahead logging (WAL) in Core Data using Apples new programming language Swift?

In ObjC I used to pass in the key value pair @"journal_mode": @"DELETE" in the options dictionary:

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

But in Swift only the same types are allowed in a NSDictionary, so mixing BOOL (that is mapped to NSNumber) and NSString is not possible.

Any ideas?

like image 404
kober Avatar asked Dec 07 '22 00:12

kober


1 Answers

These answers were close but neither were actually working for me. The following does work. The option must be as as a 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 {
    ...
}
like image 171
Mark McCorkle Avatar answered May 11 '23 01:05

Mark McCorkle