diff --git a/CoreStore/Importing Data/ImportableObject.swift b/CoreStore/Importing Data/ImportableObject.swift index a24b767..7570f32 100644 --- a/CoreStore/Importing Data/ImportableObject.swift +++ b/CoreStore/Importing Data/ImportableObject.swift @@ -53,7 +53,7 @@ public protocol ImportableObject: class { /** The data type for the import source. This is most commonly an `NSDictionary` or another external source such as an `NSUserDefaults`. */ - typealias ImportSource + associatedtype ImportSource /** Return `true` if an object should be created from `source`. Return `false` to ignore and skip `source`. The default implementation returns `true`. diff --git a/CoreStore/Importing Data/ImportableUniqueObject.swift b/CoreStore/Importing Data/ImportableUniqueObject.swift index 5c23467..d5f7dc4 100644 --- a/CoreStore/Importing Data/ImportableUniqueObject.swift +++ b/CoreStore/Importing Data/ImportableUniqueObject.swift @@ -54,12 +54,12 @@ public protocol ImportableUniqueObject: ImportableObject { /** The data type for the import source. This is most commonly an `NSDictionary` or another external source such as an `NSUserDefaults`. */ - typealias ImportSource + associatedtype ImportSource /** The data type for the entity's unique ID attribute */ - typealias UniqueIDType: NSObject + associatedtype UniqueIDType: NSObject /** The keyPath to the entity's unique ID attribute diff --git a/CoreStore/Internal/NSManagedObjectModel+Setup.swift b/CoreStore/Internal/NSManagedObjectModel+Setup.swift index 9d0bac0..ef22705 100644 --- a/CoreStore/Internal/NSManagedObjectModel+Setup.swift +++ b/CoreStore/Internal/NSManagedObjectModel+Setup.swift @@ -155,11 +155,12 @@ internal extension NSManagedObjectModel { @nonobjc internal func entityTypesMapping() -> [String: NSManagedObject.Type] { - return self.entityNameMapping.reduce([:]) { (var mapping, pair) in + var mapping = [String: NSManagedObject.Type]() + self.entityNameMapping.forEach { (className, entityName) in - mapping[pair.1] = (NSClassFromString(pair.0)! as! NSManagedObject.Type) - return mapping + mapping[entityName] = (NSClassFromString(className)! as! NSManagedObject.Type) } + return mapping } @nonobjc internal func mergedModels() -> [NSManagedObjectModel] { @@ -249,15 +250,16 @@ internal extension NSManagedObjectModel { return mapping as! [String: String] } - let mapping = self.entities.reduce([String: String]()) { - (var mapping, entityDescription) -> [String: String] in + var mapping = [String: String]() + self.entities.forEach { - if let entityName = entityDescription.name { + guard let entityName = $0.name else { - let className = entityDescription.managedObjectClassName - mapping[className] = entityName + return } - return mapping + + let className = $0.managedObjectClassName + mapping[className] = entityName } setAssociatedCopiedObject( mapping as NSDictionary, diff --git a/CoreStore/Logging/CoreStore+Logging.swift b/CoreStore/Logging/CoreStore+Logging.swift index 5bfe79c..76a3bc7 100644 --- a/CoreStore/Logging/CoreStore+Logging.swift +++ b/CoreStore/Logging/CoreStore+Logging.swift @@ -38,7 +38,7 @@ public extension CoreStore { // MARK: Internal - internal static func log(level: LogLevel, message: String, fileName: StaticString = __FILE__, lineNumber: Int = __LINE__, functionName: StaticString = __FUNCTION__) { + internal static func log(level: LogLevel, message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) { self.logger.log( level: level, @@ -49,7 +49,7 @@ public extension CoreStore { ) } - internal static func handleError(error: NSError, _ message: String, fileName: StaticString = __FILE__, lineNumber: Int = __LINE__, functionName: StaticString = __FUNCTION__) { + internal static func handleError(error: NSError, _ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) { self.logger.handleError( error: error, @@ -60,7 +60,7 @@ public extension CoreStore { ) } - internal static func assert(@autoclosure condition: () -> Bool, _ message: String, fileName: StaticString = __FILE__, lineNumber: Int = __LINE__, functionName: StaticString = __FUNCTION__) { + internal static func assert(@autoclosure condition: () -> Bool, _ message: String, fileName: StaticString = #file, lineNumber: Int = #line, functionName: StaticString = #function) { self.logger.assert( condition, diff --git a/CoreStore/Migrating/MigrationChain.swift b/CoreStore/Migrating/MigrationChain.swift index b57cfd6..eb1a3a0 100644 --- a/CoreStore/Migrating/MigrationChain.swift +++ b/CoreStore/Migrating/MigrationChain.swift @@ -111,15 +111,17 @@ public struct MigrationChain: NilLiteralConvertible, StringLiteralConvertible, D public init(dictionaryLiteral elements: (String, String)...) { var valid = true - let versionTree = elements.reduce([String: String]()) { (var versionTree, tuple: (String, String)) -> [String: String] in + var versionTree = [String: String]() + elements.forEach { (sourceVersion, destinationVersion) in - if let _ = versionTree.updateValue(tuple.1, forKey: tuple.0) { + guard let _ = versionTree.updateValue(destinationVersion, forKey: sourceVersion) else { - CoreStore.assert(false, "\(typeName(MigrationChain))'s migration chain could not be created due to ambiguous version paths.") - - valid = false + return } - return versionTree + + CoreStore.assert(false, "\(typeName(MigrationChain))'s migration chain could not be created due to ambiguous version paths.") + + valid = false } let leafVersions = Set( elements.filter { (tuple: (String, String)) -> Bool in diff --git a/CoreStore/Observing/ListObserver.swift b/CoreStore/Observing/ListObserver.swift index 67ced6a..61c11c8 100644 --- a/CoreStore/Observing/ListObserver.swift +++ b/CoreStore/Observing/ListObserver.swift @@ -45,7 +45,7 @@ public protocol ListObserver: class { /** The `NSManagedObject` type for the observed list */ - typealias ListEntityType: NSManagedObject + associatedtype ListEntityType: NSManagedObject /** Handles processing just before a change to the observed list occurs diff --git a/CoreStore/Observing/ObjectObserver.swift b/CoreStore/Observing/ObjectObserver.swift index 0188b0a..ca662bd 100644 --- a/CoreStore/Observing/ObjectObserver.swift +++ b/CoreStore/Observing/ObjectObserver.swift @@ -42,7 +42,7 @@ public protocol ObjectObserver: class { /** The `NSManagedObject` type for the observed object */ - typealias ObjectEntityType: NSManagedObject + associatedtype ObjectEntityType: NSManagedObject /** Handles processing just before a change to the observed `object` occurs