refactor some internal methods. renamed addInMemoryStore to addInMemoryStoreAndWait to reflect synchronicity.

This commit is contained in:
John Rommel Estropia
2015-07-25 23:05:48 +09:00
parent edc51de030
commit 106789d592
9 changed files with 173 additions and 44 deletions

View File

@@ -38,9 +38,9 @@ public extension CoreStore {
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`.
- returns: the `NSPersistentStore` added to the stack.
*/
public static func addInMemoryStore(configuration configuration: String? = nil) throws -> NSPersistentStore {
public static func addInMemoryStoreAndWait(configuration configuration: String? = nil) throws -> NSPersistentStore {
return try self.defaultStack.addInMemoryStore(configuration: configuration)
return try self.defaultStack.addInMemoryStoreAndWait(configuration: configuration)
}
/**

View File

@@ -87,7 +87,7 @@ public final class DataStack {
- parameter configuration: an optional configuration name from the model file. If not specified, defaults to `nil`.
- returns: the `NSPersistentStore` added to the stack.
*/
public func addInMemoryStore(configuration configuration: String? = nil) throws -> NSPersistentStore {
public func addInMemoryStoreAndWait(configuration configuration: String? = nil) throws -> NSPersistentStore {
let coordinator = self.coordinator;
@@ -224,31 +224,9 @@ public final class DataStack {
}
if let error = storeError
where (
resetStoreOnMigrationFailure
&& (error.code == NSPersistentStoreIncompatibleVersionHashError
|| error.code == NSMigrationMissingSourceModelError
|| error.code == NSMigrationError)
&& error.domain == NSCocoaErrorDomain
) {
where (resetStoreOnMigrationFailure && error.isCoreDataMigrationError) {
do {
try fileManager.removeItemAtURL(fileURL)
}
catch _ { }
do {
try fileManager.removeItemAtPath(fileURL.path!.stringByAppendingString("-shm"))
}
catch _ { }
do {
try fileManager.removeItemAtPath(fileURL.path!.stringByAppendingString("-wal"))
}
catch _ { }
fileManager.removeSQLiteStoreAtURL(fileURL)
var store: NSPersistentStore?
coordinator.performBlockAndWait {