From b7a602fc67ea6725f6653c9499ed5e8165b0be1a Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Sun, 29 Jul 2018 23:33:51 +0900 Subject: [PATCH] iOS 11 Core Data changes --- Sources/SQLiteStore.swift | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Sources/SQLiteStore.swift b/Sources/SQLiteStore.swift index 7abebde..5d4113d 100644 --- a/Sources/SQLiteStore.swift +++ b/Sources/SQLiteStore.swift @@ -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) }