WIP: StorageInterface

This commit is contained in:
John Rommel Estropia
2016-03-08 07:55:15 +09:00
parent 34495d7163
commit 2f8c100cb6
6 changed files with 21 additions and 22 deletions

View File

@@ -154,8 +154,7 @@ public final class DataStack {
URL: nil,
options: storage.storeOptions
)
self.updateMetadataForPersistentStore(persistentStore)
storage.internalStore = persistentStore
self.updateMetadataForStorage(storage, persistentStore: persistentStore)
return storage
}
catch {
@@ -237,7 +236,12 @@ public final class DataStack {
}
catch let error as NSError where storage.resetStoreOnModelMismatch && error.isCoreDataMigrationError {
try storage.eraseStorageAndWait()
let metadata = try NSPersistentStoreCoordinator.metadataForPersistentStoreOfType(
storage.dynamicType.storeType,
URL: fileURL,
options: storage.storeOptions
)
try _ = self.model[metadata].flatMap(storage.eraseStorageAndWait)
return try coordinator.addPersistentStoreWithType(
storage.dynamicType.storeType,
@@ -247,8 +251,7 @@ public final class DataStack {
)
}
}
self.updateMetadataForPersistentStore(persistentStore)
storage.internalStore = persistentStore
self.updateMetadataForStorage(storage, persistentStore: persistentStore)
return storage
}
catch {
@@ -335,7 +338,9 @@ public final class DataStack {
return returnValue
}
internal func updateMetadataForPersistentStore(persistentStore: NSPersistentStore) {
internal func updateMetadataForStorage(storage: StorageInterface, persistentStore: NSPersistentStore) {
storage.internalStore = persistentStore
self.storeMetadataUpdateQueue.barrierAsync {

View File

@@ -95,14 +95,14 @@ public class SQLiteStore: LocalStorage, DefaultInitializableStore {
public var internalStore: NSPersistentStore?
public func eraseStorageAndWait() throws {
public func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws {
// TODO: check if attached to persistent store
let fileURL = self.fileURL
try autoreleasepool {
let journalUpdatingCoordinator = NSPersistentStoreCoordinator()
let journalUpdatingCoordinator = NSPersistentStoreCoordinator(managedObjectModel: soureModel)
let store = try journalUpdatingCoordinator.addPersistentStoreWithType(
self.dynamicType.storeType,
configuration: self.configuration,

View File

@@ -55,5 +55,5 @@ public protocol LocalStorage: StorageInterface {
var mappingModelBundles: [NSBundle] { get }
var resetStoreOnModelMismatch: Bool { get }
func eraseStorageAndWait() throws
func eraseStorageAndWait(soureModel soureModel: NSManagedObjectModel) throws
}