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

后端 未结 3 962
你的背包
你的背包 2021-01-06 04:22

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 @\"jour

3条回答
  •  迷失自我
    2021-01-06 05:05

    One hint, make sure you pass a Dictionary into NSSQLitePragmasOption. e.g.

    url = NSBundle.mainBundle().URLForResource(name, withExtension: "momd")
    let coordinator = NSPersistentStoreCoordinator(managedObjectModel: NSManagedObjectModel(contentsOfURL: url!)!)
    
    var err: NSError? = nil
    url = dataDir.URLByAppendingPathComponent(name + ".sqlite")
    options = [NSMigratePersistentStoresAutomaticallyOption: true, NSInferMappingModelAutomaticallyOption: true, NSSQLitePragmasOption: ["journal_mode": "DELETE"]]
    coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: options, error: &err)
    

提交回复
热议问题