From 21a524d725b1ddf7e699b3c2868bdab53faa96dc Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Fri, 28 Aug 2015 08:09:06 +0900 Subject: [PATCH] tidy up --- .../Concrete Clauses/Select.swift | 24 +-- CoreStore/Internal/MigrationManager.swift | 7 +- CoreStore/Internal/NSFileManager+Setup.swift | 20 +- .../NSManagedObjectContext+CoreStore.swift | 17 +- .../NSManagedObjectContext+Querying.swift | 16 +- .../NSManagedObjectContext+Setup.swift | 2 +- .../NSManagedObjectContext+Transaction.swift | 4 +- .../Internal/NSManagedObjectModel+Setup.swift | 13 +- CoreStore/Migrating/DataStack+Migration.swift | 40 ++-- CoreStore/Migrating/MigrationChain.swift | 12 +- CoreStore/Observing/ListMonitor.swift | 203 ++++++++++-------- CoreStore/Observing/ObjectMonitor.swift | 93 ++++---- CoreStore/Setting Up/DataStack.swift | 40 ++-- 13 files changed, 240 insertions(+), 251 deletions(-) diff --git a/CoreStore/Fetching and Querying/Concrete Clauses/Select.swift b/CoreStore/Fetching and Querying/Concrete Clauses/Select.swift index 3653164..518f9b0 100644 --- a/CoreStore/Fetching and Querying/Concrete Clauses/Select.swift +++ b/CoreStore/Fetching and Querying/Concrete Clauses/Select.swift @@ -406,11 +406,11 @@ extension Int8: SelectValueResultType { public static func fromResultObject(result: AnyObject) -> Int8? { - if let value = (result as? NSNumber)?.longLongValue { + guard let value = (result as? NSNumber)?.longLongValue else { - return numericCast(value) as Int8 + return nil } - return nil + return numericCast(value) as Int8 } } @@ -426,11 +426,11 @@ extension Int16: SelectValueResultType { public static func fromResultObject(result: AnyObject) -> Int16? { - if let value = (result as? NSNumber)?.longLongValue { + guard let value = (result as? NSNumber)?.longLongValue else { - return numericCast(value) as Int16 + return nil } - return nil + return numericCast(value) as Int16 } } @@ -446,11 +446,11 @@ extension Int32: SelectValueResultType { public static func fromResultObject(result: AnyObject) -> Int32? { - if let value = (result as? NSNumber)?.longLongValue { + guard let value = (result as? NSNumber)?.longLongValue else { - return numericCast(value) as Int32 + return nil } - return nil + return numericCast(value) as Int32 } } @@ -482,11 +482,11 @@ extension Int: SelectValueResultType { public static func fromResultObject(result: AnyObject) -> Int? { - if let value = (result as? NSNumber)?.longLongValue { + guard let value = (result as? NSNumber)?.longLongValue else { - return numericCast(value) as Int + return nil } - return nil + return numericCast(value) as Int } } diff --git a/CoreStore/Internal/MigrationManager.swift b/CoreStore/Internal/MigrationManager.swift index 9f453b2..2ec8abe 100644 --- a/CoreStore/Internal/MigrationManager.swift +++ b/CoreStore/Internal/MigrationManager.swift @@ -37,11 +37,12 @@ internal final class MigrationManager: NSMigrationManager, NSProgressReporting { super.didChangeValueForKey(key) - if key == "migrationProgress" { + guard key == "migrationProgress" else { - let progress = self.progress - progress.completedUnitCount = Int64(Float(progress.totalUnitCount) * self.migrationProgress) + return } + let progress = self.progress + progress.completedUnitCount = Int64(Float(progress.totalUnitCount) * self.migrationProgress) } diff --git a/CoreStore/Internal/NSFileManager+Setup.swift b/CoreStore/Internal/NSFileManager+Setup.swift index e5a1181..92d5bb2 100644 --- a/CoreStore/Internal/NSFileManager+Setup.swift +++ b/CoreStore/Internal/NSFileManager+Setup.swift @@ -17,22 +17,10 @@ internal extension NSFileManager { internal func removeSQLiteStoreAtURL(fileURL: NSURL) { - do { - - try self.removeItemAtURL(fileURL) - } - catch _ { } + _ = try? self.removeItemAtURL(fileURL) - do { - - try self.removeItemAtPath(fileURL.path!.stringByAppendingString("-shm")) - } - catch _ { } - - do { - - try self.removeItemAtPath(fileURL.path!.stringByAppendingString("-wal")) - } - catch _ { } + let filePath = fileURL.path! + _ = try? self.removeItemAtPath(filePath.stringByAppendingString("-shm")) + _ = try? self.removeItemAtPath(filePath.stringByAppendingString("-wal")) } } \ No newline at end of file diff --git a/CoreStore/Internal/NSManagedObjectContext+CoreStore.swift b/CoreStore/Internal/NSManagedObjectContext+CoreStore.swift index cf69c65..30ee6a6 100644 --- a/CoreStore/Internal/NSManagedObjectContext+CoreStore.swift +++ b/CoreStore/Internal/NSManagedObjectContext+CoreStore.swift @@ -61,14 +61,14 @@ internal extension NSManagedObjectContext { internal func entityDescriptionForEntityClass(entity: AnyClass) -> NSEntityDescription? { - if let entityName = self.parentStack?.entityNameForEntityClass(entity) { - - return NSEntityDescription.entityForName( - entityName, - inManagedObjectContext: self - ) + guard let entityName = self.parentStack?.entityNameForEntityClass(entity) else { + + return nil } - return nil + return NSEntityDescription.entityForName( + entityName, + inManagedObjectContext: self + ) } internal func setupForCoreStoreWithContextName(contextName: String) { @@ -83,7 +83,7 @@ internal extension NSManagedObjectContext { let context = note.object as! NSManagedObjectContext let insertedObjects = context.insertedObjects let numberOfInsertedObjects = insertedObjects.count - if numberOfInsertedObjects <= 0 { + guard numberOfInsertedObjects > 0 else { return } @@ -91,7 +91,6 @@ internal extension NSManagedObjectContext { do { try context.obtainPermanentIDsForObjects(Array(insertedObjects)) - return } catch { diff --git a/CoreStore/Internal/NSManagedObjectContext+Querying.swift b/CoreStore/Internal/NSManagedObjectContext+Querying.swift index 8e5a26e..cbce07e 100644 --- a/CoreStore/Internal/NSManagedObjectContext+Querying.swift +++ b/CoreStore/Internal/NSManagedObjectContext+Querying.swift @@ -37,24 +37,17 @@ internal extension NSManagedObjectContext { if object.objectID.temporaryID { - var objectIDError: NSError? - let didSucceed = withExtendedLifetime(self) { (context: NSManagedObjectContext) -> Bool in + do { - do { + try withExtendedLifetime(self) { (context: NSManagedObjectContext) -> Void in try context.obtainPermanentIDsForObjects([object]) - return true - } - catch { - - objectIDError = error as NSError - return false } } - if didSucceed != true { + catch { CoreStore.handleError( - objectIDError ?? NSError(coreStoreErrorCode: .UnknownError), + error as NSError, "Failed to obtain permanent ID for object." ) return nil @@ -75,7 +68,6 @@ internal extension NSManagedObjectContext { return nil } } - internal func fetchOne(from: From, _ fetchClauses: FetchClause...) -> T? { diff --git a/CoreStore/Internal/NSManagedObjectContext+Setup.swift b/CoreStore/Internal/NSManagedObjectContext+Setup.swift index 9db9f20..c6c3563 100644 --- a/CoreStore/Internal/NSManagedObjectContext+Setup.swift +++ b/CoreStore/Internal/NSManagedObjectContext+Setup.swift @@ -46,7 +46,7 @@ internal extension NSManagedObjectContext { } set { - if self.parentContext != nil { + guard self.parentContext == nil else { return } diff --git a/CoreStore/Internal/NSManagedObjectContext+Transaction.swift b/CoreStore/Internal/NSManagedObjectContext+Transaction.swift index a1636c7..2a63722 100644 --- a/CoreStore/Internal/NSManagedObjectContext+Transaction.swift +++ b/CoreStore/Internal/NSManagedObjectContext+Transaction.swift @@ -71,7 +71,7 @@ internal extension NSManagedObjectContext { self.performBlockAndWait { [unowned self] () -> Void in - if !self.hasChanges { + guard self.hasChanges else { return } @@ -115,7 +115,7 @@ internal extension NSManagedObjectContext { self.performBlock { () -> Void in - if !self.hasChanges { + guard self.hasChanges else { if let completion = completion { diff --git a/CoreStore/Internal/NSManagedObjectModel+Setup.swift b/CoreStore/Internal/NSManagedObjectModel+Setup.swift index ffd82e2..68da04a 100644 --- a/CoreStore/Internal/NSManagedObjectModel+Setup.swift +++ b/CoreStore/Internal/NSManagedObjectModel+Setup.swift @@ -192,14 +192,15 @@ internal extension NSManagedObjectModel { @nonobjc internal subscript(metadata: [String: AnyObject]) -> NSManagedObjectModel? { - if let modelHashes = metadata[NSStoreModelVersionHashesKey] as? [String : NSData] { + guard let modelHashes = metadata[NSStoreModelVersionHashesKey] as? [String : NSData] else { - for modelVersion in self.modelVersions ?? [] { + return nil + } + for modelVersion in self.modelVersions ?? [] { + + if let versionModel = self[modelVersion] where modelHashes == versionModel.entityVersionHashesByName { - if let versionModel = self[modelVersion] where modelHashes == versionModel.entityVersionHashesByName { - - return versionModel - } + return versionModel } } return nil diff --git a/CoreStore/Migrating/DataStack+Migration.swift b/CoreStore/Migrating/DataStack+Migration.swift index af7c05e..eea7f81 100644 --- a/CoreStore/Migrating/DataStack+Migration.swift +++ b/CoreStore/Migrating/DataStack+Migration.swift @@ -117,34 +117,30 @@ public extension DataStack { let coordinator = self.coordinator; if let store = coordinator.persistentStoreForURL(fileURL) { - if store.type == NSSQLiteStoreType - && store.configurationName == (configuration ?? Into.defaultConfigurationName) { + guard store.type == NSSQLiteStoreType + && store.configurationName == (configuration ?? Into.defaultConfigurationName) else { - GCDQueue.Main.async { - - completion(PersistentStoreResult(store)) - } - return nil + let error = NSError(coreStoreErrorCode: .DifferentPersistentStoreExistsAtURL) + CoreStore.handleError( + error, + "Failed to add SQLite \(typeName(NSPersistentStore)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." + ) + throw error } - let error = NSError(coreStoreErrorCode: .DifferentPersistentStoreExistsAtURL) - CoreStore.handleError( - error, - "Failed to add SQLite \(typeName(NSPersistentStore)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." - ) - throw error + GCDQueue.Main.async { + + completion(PersistentStoreResult(store)) + } + return nil } let fileManager = NSFileManager.defaultManager() - do { - - try fileManager.createDirectoryAtURL( - fileURL.URLByDeletingLastPathComponent!, - withIntermediateDirectories: true, - attributes: nil - ) - } - catch _ { } + _ = try? fileManager.createDirectoryAtURL( + fileURL.URLByDeletingLastPathComponent!, + withIntermediateDirectories: true, + attributes: nil + ) do { diff --git a/CoreStore/Migrating/MigrationChain.swift b/CoreStore/Migrating/MigrationChain.swift index 79ee8c0..b48c17a 100644 --- a/CoreStore/Migrating/MigrationChain.swift +++ b/CoreStore/Migrating/MigrationChain.swift @@ -166,12 +166,10 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D var valid = true for version in elements { - if let lastVersion = lastVersion { - - if let _ = versionTree.updateValue(version, forKey: lastVersion) { + if let lastVersion = lastVersion, + let _ = versionTree.updateValue(version, forKey: lastVersion) { valid = false - } } lastVersion = version } @@ -203,11 +201,11 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D internal func nextVersionFrom(version: String) -> String? { - if let nextVersion = self.versionTree[version] where nextVersion != version { + guard let nextVersion = self.versionTree[version] where nextVersion != version else { - return nextVersion + return nil } - return nil + return nextVersion } diff --git a/CoreStore/Observing/ListMonitor.swift b/CoreStore/Observing/ListMonitor.swift index f9eeaaa..5017e57 100644 --- a/CoreStore/Observing/ListMonitor.swift +++ b/CoreStore/Observing/ListMonitor.swift @@ -321,10 +321,11 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitorWillChange(monitor) + return } + observer.listMonitorWillChange(monitor) } ) self.registerChangeNotification( @@ -333,10 +334,11 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitorDidChange(monitor) + return } + observer.listMonitorDidChange(monitor) } ) } @@ -367,10 +369,11 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitorWillChange(monitor) + return } + observer.listMonitorWillChange(monitor) } ) self.registerChangeNotification( @@ -379,10 +382,11 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitorDidChange(monitor) + return } + observer.listMonitorDidChange(monitor) } ) @@ -392,14 +396,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didInsertObject: object, - toIndexPath: newIndexPath! - ) + return } + observer.listMonitor( + monitor, + didInsertObject: object, + toIndexPath: newIndexPath! + ) } ) self.registerObjectNotification( @@ -408,14 +413,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didDeleteObject: object, - fromIndexPath: indexPath! - ) + return } + observer.listMonitor( + monitor, + didDeleteObject: object, + fromIndexPath: indexPath! + ) } ) self.registerObjectNotification( @@ -424,14 +430,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didUpdateObject: object, - atIndexPath: indexPath! - ) + return } + observer.listMonitor( + monitor, + didUpdateObject: object, + atIndexPath: indexPath! + ) } ) self.registerObjectNotification( @@ -440,15 +447,16 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didMoveObject: object, - fromIndexPath: indexPath!, - toIndexPath: newIndexPath! - ) + return } + observer.listMonitor( + monitor, + didMoveObject: object, + fromIndexPath: indexPath!, + toIndexPath: newIndexPath! + ) } ) } @@ -479,10 +487,11 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitorWillChange(monitor) + return } + observer.listMonitorWillChange(monitor) } ) self.registerChangeNotification( @@ -491,10 +500,11 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitorDidChange(monitor) + return } + observer.listMonitorDidChange(monitor) } ) @@ -504,14 +514,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didInsertObject: object, - toIndexPath: newIndexPath! - ) + return } + observer.listMonitor( + monitor, + didInsertObject: object, + toIndexPath: newIndexPath! + ) } ) self.registerObjectNotification( @@ -520,14 +531,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { - - observer.listMonitor( - monitor, - didDeleteObject: object, - fromIndexPath: indexPath! - ) + guard let observer = observer else { + + return } + observer.listMonitor( + monitor, + didDeleteObject: object, + fromIndexPath: indexPath! + ) } ) self.registerObjectNotification( @@ -536,14 +548,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didUpdateObject: object, - atIndexPath: indexPath! - ) + return } + observer.listMonitor( + monitor, + didUpdateObject: object, + atIndexPath: indexPath! + ) } ) self.registerObjectNotification( @@ -552,15 +565,16 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, object, indexPath, newIndexPath) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didMoveObject: object, - fromIndexPath: indexPath!, - toIndexPath: newIndexPath! - ) + return } + observer.listMonitor( + monitor, + didMoveObject: object, + fromIndexPath: indexPath!, + toIndexPath: newIndexPath! + ) } ) @@ -570,14 +584,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didInsertSection: sectionInfo, - toSectionIndex: sectionIndex - ) + return } + observer.listMonitor( + monitor, + didInsertSection: sectionInfo, + toSectionIndex: sectionIndex + ) } ) self.registerSectionNotification( @@ -586,14 +601,15 @@ public final class ListMonitor { toObserver: observer, callback: { [weak observer] (monitor, sectionInfo, sectionIndex) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.listMonitor( - monitor, - didDeleteSection: sectionInfo, - fromSectionIndex: sectionIndex - ) + return } + observer.listMonitor( + monitor, + didDeleteSection: sectionInfo, + fromSectionIndex: sectionIndex + ) } ) } @@ -686,10 +702,11 @@ public final class ListMonitor { object: self, closure: { [weak self] (note) -> Void in - if let strongSelf = self { + guard let strongSelf = self else { - callback(monitor: strongSelf) + return } + callback(monitor: strongSelf) } ), forKey: notificationKey, @@ -705,17 +722,18 @@ public final class ListMonitor { object: self, closure: { [weak self] (note) -> Void in - if let strongSelf = self, + guard let strongSelf = self, let userInfo = note.userInfo, - let object = userInfo[UserInfoKeyObject] as? T { + let object = userInfo[UserInfoKeyObject] as? T else { - callback( - monitor: strongSelf, - object: object, - indexPath: userInfo[UserInfoKeyIndexPath] as? NSIndexPath, - newIndexPath: userInfo[UserInfoKeyNewIndexPath] as? NSIndexPath - ) + return } + callback( + monitor: strongSelf, + object: object, + indexPath: userInfo[UserInfoKeyIndexPath] as? NSIndexPath, + newIndexPath: userInfo[UserInfoKeyNewIndexPath] as? NSIndexPath + ) } ), forKey: notificationKey, @@ -731,17 +749,18 @@ public final class ListMonitor { object: self, closure: { [weak self] (note) -> Void in - if let strongSelf = self, + guard let strongSelf = self, let userInfo = note.userInfo, let sectionInfo = userInfo[UserInfoKeySectionInfo] as? NSFetchedResultsSectionInfo, - let sectionIndex = (userInfo[UserInfoKeySectionIndex] as? NSNumber)?.integerValue { + let sectionIndex = (userInfo[UserInfoKeySectionIndex] as? NSNumber)?.integerValue else { - callback( - monitor: strongSelf, - sectionInfo: sectionInfo, - sectionIndex: sectionIndex - ) + return } + callback( + monitor: strongSelf, + sectionInfo: sectionInfo, + sectionIndex: sectionIndex + ) } ), forKey: notificationKey, diff --git a/CoreStore/Observing/ObjectMonitor.swift b/CoreStore/Observing/ObjectMonitor.swift index 3b88b71..16de676 100644 --- a/CoreStore/Observing/ObjectMonitor.swift +++ b/CoreStore/Observing/ObjectMonitor.swift @@ -28,20 +28,6 @@ import CoreData import GCDKit -private let ObjectMonitorWillChangeObjectNotification = "ObjectMonitorWillChangeObjectNotification" -private let ObjectMonitorDidDeleteObjectNotification = "ObjectMonitorDidDeleteObjectNotification" -private let ObjectMonitorDidUpdateObjectNotification = "ObjectMonitorDidUpdateObjectNotification" - -private let UserInfoKeyObject = "UserInfoKeyObject" - -private struct NotificationKey { - - static var willChangeObject: Void? - static var didDeleteObject: Void? - static var didUpdateObject: Void? -} - - // MARK: - ObjectMonitor /** @@ -100,10 +86,11 @@ public final class ObjectMonitor { toObserver: observer, callback: { [weak observer] (monitor) -> Void in - if let object = monitor.object, let observer = observer { + guard let object = monitor.object, let observer = observer else { - observer.objectMonitor(monitor, willUpdateObject: object) + return } + observer.objectMonitor(monitor, willUpdateObject: object) } ) self.registerObjectNotification( @@ -112,10 +99,11 @@ public final class ObjectMonitor { toObserver: observer, callback: { [weak observer] (monitor, object) -> Void in - if let observer = observer { + guard let observer = observer else { - observer.objectMonitor(monitor, didDeleteObject: object) + return } + observer.objectMonitor(monitor, didDeleteObject: object) } ) self.registerObjectNotification( @@ -124,27 +112,29 @@ public final class ObjectMonitor { toObserver: observer, callback: { [weak self, weak observer] (monitor, object) -> Void in - if let strongSelf = self, let observer = observer { + guard let strongSelf = self, let observer = observer else { - let previousCommitedAttributes = strongSelf.lastCommittedAttributes - let currentCommitedAttributes = object.committedValuesForKeys(nil) as! [String: NSObject] - - var changedKeys = Set() - for key in currentCommitedAttributes.keys { - - if previousCommitedAttributes[key] != currentCommitedAttributes[key] { - - changedKeys.insert(key) - } - } - - strongSelf.lastCommittedAttributes = currentCommitedAttributes - observer.objectMonitor( - monitor, - didUpdateObject: object, - changedPersistentKeys: changedKeys - ) + return } + + let previousCommitedAttributes = strongSelf.lastCommittedAttributes + let currentCommitedAttributes = object.committedValuesForKeys(nil) as! [String: NSObject] + + var changedKeys = Set() + for key in currentCommitedAttributes.keys { + + if previousCommitedAttributes[key] != currentCommitedAttributes[key] { + + changedKeys.insert(key) + } + } + + strongSelf.lastCommittedAttributes = currentCommitedAttributes + observer.objectMonitor( + monitor, + didUpdateObject: object, + changedPersistentKeys: changedKeys + ) } ) } @@ -222,10 +212,11 @@ public final class ObjectMonitor { object: self, closure: { [weak self] (note) -> Void in - if let strongSelf = self { + guard let strongSelf = self else { - callback(monitor: strongSelf) + return } + callback(monitor: strongSelf) } ), forKey: notificationKey, @@ -241,15 +232,13 @@ public final class ObjectMonitor { object: self, closure: { [weak self] (note) -> Void in - if let strongSelf = self, + guard let strongSelf = self, let userInfo = note.userInfo, - let object = userInfo[UserInfoKeyObject] as? T { + let object = userInfo[UserInfoKeyObject] as? T else { - callback( - monitor: strongSelf, - object: object - ) + return } + callback(monitor: strongSelf, object: object) } ), forKey: notificationKey, @@ -352,3 +341,17 @@ private final class FetchedResultsControllerDelegate: NSObject, NSFetchedResults self.fetchedResultsController?.delegate = nil } } + + +private let ObjectMonitorWillChangeObjectNotification = "ObjectMonitorWillChangeObjectNotification" +private let ObjectMonitorDidDeleteObjectNotification = "ObjectMonitorDidDeleteObjectNotification" +private let ObjectMonitorDidUpdateObjectNotification = "ObjectMonitorDidUpdateObjectNotification" + +private let UserInfoKeyObject = "UserInfoKeyObject" + +private struct NotificationKey { + + static var willChangeObject: Void? + static var didDeleteObject: Void? + static var didUpdateObject: Void? +} diff --git a/CoreStore/Setting Up/DataStack.swift b/CoreStore/Setting Up/DataStack.swift index 46fe6ce..394880e 100644 --- a/CoreStore/Setting Up/DataStack.swift +++ b/CoreStore/Setting Up/DataStack.swift @@ -189,31 +189,27 @@ public final class DataStack { let coordinator = self.coordinator; if let store = coordinator.persistentStoreForURL(fileURL) { - if store.type == NSSQLiteStoreType - && store.configurationName == (configuration ?? Into.defaultConfigurationName) { + guard store.type == NSSQLiteStoreType + && store.configurationName == (configuration ?? Into.defaultConfigurationName) else { - return store + let error = NSError(coreStoreErrorCode: .DifferentPersistentStoreExistsAtURL) + CoreStore.handleError( + error, + "Failed to add SQLite \(typeName(NSPersistentStore)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." + ) + + throw error } - let error = NSError(coreStoreErrorCode: .DifferentPersistentStoreExistsAtURL) - CoreStore.handleError( - error, - "Failed to add SQLite \(typeName(NSPersistentStore)) at \"\(fileURL)\" because a different \(typeName(NSPersistentStore)) at that URL already exists." - ) - - throw error + return store } let fileManager = NSFileManager.defaultManager() - do { - - try fileManager.createDirectoryAtURL( - fileURL.URLByDeletingLastPathComponent!, - withIntermediateDirectories: true, - attributes: nil - ) - } - catch _ { } + _ = try? fileManager.createDirectoryAtURL( + fileURL.URLByDeletingLastPathComponent!, + withIntermediateDirectories: true, + attributes: nil + ) var store: NSPersistentStore? var storeError: NSError? @@ -377,11 +373,7 @@ public final class DataStack { for store in self.coordinator.persistentStores { - do { - - try self.coordinator.removePersistentStore(store) - } - catch _ { } + _ = try? self.coordinator.removePersistentStore(store) } } }