README update

This commit is contained in:
John Estropia
2019-10-21 21:15:46 +09:00
parent f5fed063ee
commit 145edd5a7d
15 changed files with 129 additions and 520 deletions

View File

@@ -161,108 +161,3 @@ extension LocalStorage {
&& persistentStore.url == self.fileURL
}
}
// MARK: - CloudStorageOptions
/**
The `CloudStorageOptions` provides settings that tells the `DataStack` how to setup the persistent store for `LocalStorage` implementers.
*/
public struct CloudStorageOptions: OptionSet, ExpressibleByNilLiteral {
/**
Tells the `DataStack` that the store should not be migrated or recreated, and should simply fail on model mismatch
*/
public static let none = CloudStorageOptions(rawValue: 0)
/**
Tells the `DataStack` to delete and recreate the local store from the cloud store on model mismatch, otherwise exceptions will be thrown on failure instead
*/
public static let recreateLocalStoreOnModelMismatch = CloudStorageOptions(rawValue: 1 << 0)
/**
Tells the `DataStack` to allow lightweight migration for the store when added synchronously
*/
public static let allowSynchronousLightweightMigration = CloudStorageOptions(rawValue: 1 << 2)
// MARK: OptionSetType
public init(rawValue: Int) {
self.rawValue = rawValue
}
// MARK: RawRepresentable
public let rawValue: Int
// MARK: ExpressibleByNilLiteral
public init(nilLiteral: ()) {
self.rawValue = 0
}
}
// MARK: - CloudStorage
/**
The `CloudStorage` represents `StorageInterface`s that are synchronized from a cloud-based store.
*/
public protocol CloudStorage: StorageInterface {
/**
The `NSURL` that points to the store file
*/
var cacheFileURL: URL { get }
/**
Options that tell the `DataStack` how to setup the persistent store
*/
var cloudStorageOptions: CloudStorageOptions { get }
/**
The options dictionary for the specified `CloudStorageOptions`
*/
func dictionary(forOptions 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)
*/
func cs_eraseStorageAndWait(soureModel: NSManagedObjectModel) throws
}
// MARK: - Internal
extension CloudStorage {
internal func matchesPersistentStore(_ persistentStore: NSPersistentStore) -> Bool {
guard persistentStore.type == Self.storeType
&& persistentStore.configurationName == (self.configuration ?? DataStack.defaultConfigurationName) else {
return false
}
guard persistentStore.url == self.cacheFileURL else {
return false
}
guard let persistentStoreOptions = persistentStore.options,
let storeOptions = self.storeOptions else {
return persistentStore.options == nil && self.storeOptions == nil
}
return storeOptions.reduce(true) { (isMatch, tuple) in
let (key, value) = tuple
let obj1 = persistentStoreOptions[key] as? NSObject
let obj2 = value as? NSObject
return isMatch && (obj1 == obj2)
}
}
}