iOS 11 Core Data changes

This commit is contained in:
John Rommel Estropia
2018-07-29 23:33:51 +09:00
parent e3f9139304
commit b7a602fc67

View File

@@ -150,7 +150,15 @@ public final class SQLiteStore: LocalStorage {
[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
```
*/
public let storeOptions: [AnyHashable: Any]? = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
public let storeOptions: [AnyHashable: Any]? = autoreleasepool {
var storeOptions: [AnyHashable: Any] = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
if #available(iOS 11, OSX 10.13, *) {
storeOptions[NSBinaryStoreInsecureDecodingCompatibilityOption] = true
}
return storeOptions
}
/**
Do not call directly. Used by the `DataStack` internally.
@@ -212,11 +220,13 @@ public final class SQLiteStore: LocalStorage {
_ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: soureModelHint)) { (coordinator: NSPersistentStoreCoordinator) in
var storeOptions = self.storeOptions ?? [:]
storeOptions[NSSQLitePragmasOption] = ["journal_mode": "DELETE"]
try coordinator.addPersistentStore(
ofType: type(of: self).storeType,
configurationName: self.configuration,
at: fileURL,
options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]]
options: storeOptions
)
}
_ = try? FileManager.default.removeItem(atPath: "\(self.fileURL.path)-shm")
@@ -276,11 +286,13 @@ public final class SQLiteStore: LocalStorage {
if let soureModel = soureModelHint ?? NSManagedObjectModel.mergedModel(from: nil, forStoreMetadata: metadata) {
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
var storeOptions = self.storeOptions ?? [:]
storeOptions[NSSQLitePragmasOption] = ["journal_mode": "DELETE"]
let store = try journalUpdatingCoordinator.addPersistentStore(
ofType: type(of: self).storeType,
configurationName: self.configuration,
at: fileURL,
options: [NSSQLitePragmasOption: ["journal_mode": "DELETE"]]
options: storeOptions
)
try journalUpdatingCoordinator.remove(store)
}