WIP: broken generics

This commit is contained in:
John Estropia
2016-09-06 20:16:46 +09:00
parent b502895d63
commit 82de482191
95 changed files with 610 additions and 677 deletions

View File

@@ -85,12 +85,12 @@ public class ICloudStore: CloudStorage {
)
let fileManager = FileManager.default
guard let cacheFileURL = fileManager.urlForUbiquityContainerIdentifier(ubiquitousContainerID) else {
guard let cacheFileURL = fileManager.url(forUbiquityContainerIdentifier: ubiquitousContainerID) else {
return nil
}
var storeOptions: [String: AnyObject] = [
var storeOptions: [String: Any] = [
NSSQLitePragmasOption: ["journal_mode": "WAL"],
NSPersistentStoreUbiquitousContentNameKey: ubiquitousContentName
]
@@ -265,7 +265,7 @@ public class ICloudStore: CloudStorage {
[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
```
*/
public let storeOptions: [String: AnyObject]?
public let storeOptions: [AnyHashable: Any]?
/**
Do not call directly. Used by the `DataStack` internally.
@@ -312,7 +312,7 @@ public class ICloudStore: CloudStorage {
NotificationCenter.default.post(
name: notification,
object: self,
userInfo: [String(DataStack.self): dataStack]
userInfo: [String(describing: DataStack.self): dataStack]
)
}
),
@@ -354,7 +354,7 @@ public class ICloudStore: CloudStorage {
NotificationCenter.default.post(
name: notification,
object: self,
userInfo: [String(DataStack.self): dataStack]
userInfo: [String(describing: DataStack.self): dataStack]
)
}
),
@@ -400,7 +400,7 @@ public class ICloudStore: CloudStorage {
/**
The options dictionary for the specified `CloudStorageOptions`
*/
public func storeOptionsForOptions(_ options: CloudStorageOptions) -> [String: AnyObject]? {
public func storeOptionsForOptions(_ options: CloudStorageOptions) -> [AnyHashable: Any]? {
if options == .none {
@@ -453,10 +453,10 @@ public class ICloudStore: CloudStorage {
// MARK: Private
private struct Static {
fileprivate struct Static {
private static var persistentStoreCoordinatorWillChangeStores: Void?
private static var persistentStoreCoordinatorDidChangeStores: Void?
fileprivate static var persistentStoreCoordinatorWillChangeStores: Void?
fileprivate static var persistentStoreCoordinatorDidChangeStores: Void?
}
private var willFinishInitialImportKey: Void?
@@ -480,7 +480,7 @@ public class ICloudStore: CloudStorage {
guard let `self` = self,
let observer = observer,
let dataStack = note.userInfo?[String(DataStack.self)] as? DataStack,
let dataStack = note.userInfo?[String(describing: DataStack.self)] as? DataStack,
self.dataStack === dataStack else {
return
@@ -497,16 +497,16 @@ public class ICloudStore: CloudStorage {
// MARK: - Notification Keys
private extension Notification.Name {
fileprivate extension Notification.Name {
private static let iCloudUbiquitousStoreWillFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreWillFinishInitialImport")
private static let iCloudUbiquitousStoreDidFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreDidFinishInitialImport")
private static let iCloudUbiquitousStoreWillAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillAddAccount")
private static let iCloudUbiquitousStoreDidAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidAddAccount")
private static let iCloudUbiquitousStoreWillRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveAccount")
private static let iCloudUbiquitousStoreDidRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveAccount")
private static let iCloudUbiquitousStoreWillRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveContent")
private static let iCloudUbiquitousStoreDidRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveContent")
fileprivate static let iCloudUbiquitousStoreWillFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreWillFinishInitialImport")
fileprivate static let iCloudUbiquitousStoreDidFinishInitialImport = Notification.Name(rawValue: "iCloudUbiquitousStoreDidFinishInitialImport")
fileprivate static let iCloudUbiquitousStoreWillAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillAddAccount")
fileprivate static let iCloudUbiquitousStoreDidAddAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidAddAccount")
fileprivate static let iCloudUbiquitousStoreWillRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveAccount")
fileprivate static let iCloudUbiquitousStoreDidRemoveAccount = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveAccount")
fileprivate static let iCloudUbiquitousStoreWillRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreWillRemoveContent")
fileprivate static let iCloudUbiquitousStoreDidRemoveContent = Notification.Name(rawValue: "iCloudUbiquitousStoreDidRemoveContent")
}
#endif

View File

@@ -69,7 +69,7 @@ public final class InMemoryStore: StorageInterface, DefaultInitializableStore {
/**
The options dictionary for the `NSPersistentStore`. For `InMemoryStore`s, this is always set to `nil`.
*/
public let storeOptions: [String: AnyObject]? = nil
public let storeOptions: [AnyHashable: Any]? = nil
/**
Do not call directly. Used by the `DataStack` internally.

View File

@@ -63,7 +63,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
*/
public init(fileName: String, configuration: String? = nil, mappingModelBundles: [Bundle] = Bundle.allBundles, localStorageOptions: LocalStorageOptions = nil) {
self.fileURL = try! LegacySQLiteStore.defaultRootDirectory.appendingPathComponent(
self.fileURL = LegacySQLiteStore.defaultRootDirectory.appendingPathComponent(
fileName,
isDirectory: false
)
@@ -99,7 +99,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
/**
The options dictionary for the specified `LocalStorageOptions`
*/
public func storeOptionsForOptions(_ options: LocalStorageOptions) -> [String: AnyObject]? {
public func storeOptionsForOptions(_ options: LocalStorageOptions) -> [AnyHashable: Any]? {
if options == .none {
@@ -126,7 +126,7 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
```
*/
public let storeOptions: [String: AnyObject]? = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
public let storeOptions: [AnyHashable: Any]? = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
/**
Do not call directly. Used by the `DataStack` internally.
@@ -184,12 +184,12 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
let fileManager = FileManager.default
do {
let temporaryFile = try URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!)
let temporaryFile = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!)
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true)
.appendingPathComponent("trash", isDirectory: true)
.appendingPathComponent(UUID().uuidString, isDirectory: false)
try fileManager.createDirectory(
at: try temporaryFile.deletingLastPathComponent(),
at: temporaryFile.deletingLastPathComponent(),
withIntermediateDirectories: true,
attributes: nil
)
@@ -217,13 +217,12 @@ public final class LegacySQLiteStore: LocalStorage, DefaultInitializableStore {
let systemDirectorySearchPath = FileManager.SearchPathDirectory.applicationSupportDirectory
#endif
return FileManager.default.urlsForDirectory(
systemDirectorySearchPath,
inDomains: .userDomainMask
).first!
return FileManager.default.urls(
for: systemDirectorySearchPath,
in: .userDomainMask).first!
}()
internal static let defaultFileURL = try! LegacySQLiteStore.defaultRootDirectory
internal static let defaultFileURL = LegacySQLiteStore.defaultRootDirectory
.appendingPathComponent(DataStack.applicationName, isDirectory: false)
.appendingPathExtension("sqlite")

View File

@@ -62,7 +62,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
*/
public init(fileName: String, configuration: String? = nil, mappingModelBundles: [Bundle] = Bundle.allBundles, localStorageOptions: LocalStorageOptions = nil) {
self.fileURL = try! SQLiteStore.defaultRootDirectory
self.fileURL = SQLiteStore.defaultRootDirectory
.appendingPathComponent(fileName, isDirectory: false)
self.configuration = configuration
self.mappingModelBundles = mappingModelBundles
@@ -104,7 +104,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
[NSSQLitePragmasOption: ["journal_mode": "WAL"]]
```
*/
public let storeOptions: [String: AnyObject]? = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
public let storeOptions: [AnyHashable: Any]? = [NSSQLitePragmasOption: ["journal_mode": "WAL"]]
/**
Do not call directly. Used by the `DataStack` internally.
@@ -143,7 +143,7 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
/**
The options dictionary for the specified `LocalStorageOptions`
*/
public func storeOptionsForOptions(_ options: LocalStorageOptions) -> [String: AnyObject]? {
public func storeOptionsForOptions(_ options: LocalStorageOptions) -> [AnyHashable: Any]? {
if options == .none {
@@ -181,12 +181,12 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
let fileManager = FileManager.default
do {
let temporaryFile = try URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!)
let temporaryFile = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first!)
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack", isDirectory: true)
.appendingPathComponent("trash", isDirectory: true)
.appendingPathComponent(UUID().uuidString, isDirectory: false)
try fileManager.createDirectory(
at: try temporaryFile.deletingLastPathComponent(),
at: temporaryFile.deletingLastPathComponent(),
withIntermediateDirectories: true,
attributes: nil
)
@@ -214,10 +214,11 @@ public final class SQLiteStore: LocalStorage, DefaultInitializableStore {
let systemDirectorySearchPath = FileManager.SearchPathDirectory.applicationSupportDirectory
#endif
let defaultSystemDirectory = FileManager.default
.urlsForDirectory(systemDirectorySearchPath, inDomains: .userDomainMask).first!
let defaultSystemDirectory = FileManager.default.urls(
for: systemDirectorySearchPath,
in: .userDomainMask).first!
return try! defaultSystemDirectory.appendingPathComponent(
return defaultSystemDirectory.appendingPathComponent(
Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack",
isDirectory: true
)

View File

@@ -46,7 +46,7 @@ public protocol StorageInterface: class {
/**
The options dictionary for the `NSPersistentStore`
*/
var storeOptions: [String: AnyObject]? { get }
var storeOptions: [AnyHashable: Any]? { get }
// MARK: Internal (Do not call these directly)
@@ -153,7 +153,7 @@ public protocol LocalStorage: StorageInterface {
/**
The options dictionary for the specified `LocalStorageOptions`
*/
func storeOptionsForOptions(_ options: LocalStorageOptions) -> [String: AnyObject]?
func storeOptionsForOptions(_ options: LocalStorageOptions) -> [AnyHashable: Any]?
/**
Called by the `DataStack` to perform actual deletion of the store file from disk. **Do not call directly!** The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (SQLite stores for example, can convert WAL journaling mode to DELETE before deleting)
@@ -237,7 +237,7 @@ public protocol CloudStorage: StorageInterface {
/**
The options dictionary for the specified `CloudStorageOptions`
*/
func storeOptionsForOptions(_ options: CloudStorageOptions) -> [String: AnyObject]?
func storeOptionsForOptions(_ options: CloudStorageOptions) -> [AnyHashable: Any]?
/**
Called by the `DataStack` to perform actual deletion of the store file from disk. **Do not call directly!** The `sourceModel` argument is a hint for the existing store's model version. Implementers can use the `sourceModel` to perform necessary store operations. (Cloud stores for example, can set the NSPersistentStoreRemoveUbiquitousMetadataOption option before deleting)