mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 22:30:34 +01:00
deleted unnecessary Equatable and Hashable custom implementations
This commit is contained in:
@@ -102,8 +102,10 @@ public final class CSObjectMonitor: NSObject {
|
||||
// MARK: NSObject
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.bridgeToSwift.hashValue
|
||||
|
||||
var hasher = Hasher()
|
||||
self.bridgeToSwift.hash(into: &hasher)
|
||||
return hasher.finalize()
|
||||
}
|
||||
|
||||
public override func isEqual(_ object: Any?) -> Bool {
|
||||
|
||||
@@ -173,9 +173,6 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
||||
|
||||
case (let error1 as NSError, let error2 as NSError):
|
||||
return error1.isEqual(error2)
|
||||
|
||||
default:
|
||||
return false // shouldn't happen
|
||||
}
|
||||
|
||||
case (.userCancelled, .userCancelled):
|
||||
@@ -188,35 +185,37 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
let code = self._code
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self._code)
|
||||
switch self {
|
||||
|
||||
|
||||
case .unknown:
|
||||
return code.hashValue
|
||||
|
||||
break
|
||||
|
||||
case .differentStorageExistsAtURL(let existingPersistentStoreURL):
|
||||
return code.hashValue ^ existingPersistentStoreURL.hashValue
|
||||
|
||||
hasher.combine(existingPersistentStoreURL)
|
||||
|
||||
case .mappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion):
|
||||
return code.hashValue ^ localStoreURL.hashValue ^ targetModel.hashValue ^ targetModelVersion.hashValue
|
||||
|
||||
hasher.combine(localStoreURL)
|
||||
hasher.combine(targetModel)
|
||||
hasher.combine(targetModelVersion)
|
||||
|
||||
case .progressiveMigrationRequired(let localStoreURL):
|
||||
return code.hashValue ^ localStoreURL.hashValue
|
||||
|
||||
hasher.combine(localStoreURL)
|
||||
|
||||
case .internalError(let nsError):
|
||||
return code.hashValue ^ nsError.hashValue
|
||||
|
||||
hasher.combine(nsError)
|
||||
|
||||
case .userError(let error):
|
||||
return code.hashValue ^ (error as NSError).hashValue
|
||||
|
||||
hasher.combine(error as NSError)
|
||||
|
||||
case .userCancelled:
|
||||
return code.hashValue
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
|
||||
@@ -100,11 +100,12 @@ open /*abstract*/ class CoreStoreObject: DynamicObject, Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return ObjectIdentifier(self).hashValue
|
||||
^ (self.isMeta ? 0 : self.rawObject!.hashValue)
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.isMeta)
|
||||
hasher.combine(ObjectIdentifier(self))
|
||||
hasher.combine(self.rawObject)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -146,24 +146,28 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
switch self {
|
||||
|
||||
case .deleteEntity(let sourceEntity):
|
||||
return sourceEntity.hashValue
|
||||
hasher.combine(0)
|
||||
hasher.combine(sourceEntity)
|
||||
|
||||
case .insertEntity(let destinationEntity):
|
||||
return destinationEntity.hashValue
|
||||
hasher.combine(1)
|
||||
hasher.combine(destinationEntity)
|
||||
|
||||
case .copyEntity(let sourceEntity, let destinationEntity):
|
||||
return sourceEntity.hashValue
|
||||
^ destinationEntity.hashValue
|
||||
hasher.combine(2)
|
||||
hasher.combine(sourceEntity)
|
||||
hasher.combine(destinationEntity)
|
||||
|
||||
case .transformEntity(let sourceEntity, let destinationEntity, _):
|
||||
return sourceEntity.hashValue
|
||||
^ destinationEntity.hashValue
|
||||
hasher.combine(3)
|
||||
hasher.combine(sourceEntity)
|
||||
hasher.combine(destinationEntity)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,16 +328,17 @@ public class CustomSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
||||
|
||||
return lhs.sourceVersion == rhs.sourceVersion
|
||||
&& lhs.destinationVersion == rhs.destinationVersion
|
||||
&& type(of: lhs) == type(of: rhs)
|
||||
&& cs_dynamicType(of: lhs) == cs_dynamicType(of: rhs)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return self.sourceVersion.hashValue
|
||||
^ self.destinationVersion.hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.sourceVersion)
|
||||
hasher.combine(self.destinationVersion)
|
||||
hasher.combine(ObjectIdentifier(cs_dynamicType(of: self)))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -167,15 +167,13 @@ public /*abstract*/ class DynamicEntity: Hashable {
|
||||
}
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return ObjectIdentifier(self.type).hashValue
|
||||
^ self.entityName.hashValue
|
||||
^ self.isAbstract.hashValue
|
||||
^ (self.versionHashModifier ?? "").hashValue
|
||||
// ^ self.indexes.hashValue
|
||||
// ^ self.uniqueConstraints.hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(ObjectIdentifier(self.type))
|
||||
hasher.combine(self.entityName)
|
||||
hasher.combine(self.isAbstract)
|
||||
hasher.combine(self.versionHashModifier ?? "")
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -85,22 +85,4 @@ internal struct EntityIdentifier: Hashable {
|
||||
self.interfacedClassName = entityDescription.managedObjectClassName!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
static func == (lhs: EntityIdentifier, rhs: EntityIdentifier) -> Bool {
|
||||
|
||||
return lhs.category == rhs.category
|
||||
&& lhs.interfacedClassName == rhs.interfacedClassName
|
||||
}
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
var hashValue: Int {
|
||||
|
||||
return self.category.hashValue
|
||||
^ self.interfacedClassName.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,10 +96,10 @@ public struct GroupBy<D: DynamicObject>: GroupByClause, QueryClause, Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return (self.keyPaths as NSArray).hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.keyPaths)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,10 +43,10 @@ public final class InferredSchemaMappingProvider: Hashable, SchemaMappingProvide
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return ObjectIdentifier(type(of: self)).hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(ObjectIdentifier(type(of: self)))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -112,12 +112,12 @@ public struct Into<D: DynamicObject>: Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return ObjectIdentifier(self.entityClass).hashValue
|
||||
^ (self.configuration?.hashValue ?? 0)
|
||||
^ self.inferStoreIfPossible.hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(ObjectIdentifier(self.entityClass))
|
||||
hasher.combine(self.configuration)
|
||||
hasher.combine(self.inferStoreIfPossible)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -617,10 +617,10 @@ public final class ListMonitor<D: DynamicObject>: Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return ObjectIdentifier(self).hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(ObjectIdentifier(self))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -68,40 +68,6 @@ public enum MigrationResult: Hashable {
|
||||
}
|
||||
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
public static func == (lhs: MigrationResult, rhs: MigrationResult) -> Bool {
|
||||
|
||||
switch (lhs, rhs) {
|
||||
|
||||
case (.success(let migrationTypes1), .success(let migrationTypes2)):
|
||||
return migrationTypes1 == migrationTypes2
|
||||
|
||||
case (.failure(let error1), .failure(let error2)):
|
||||
return error1 == error2
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
switch self {
|
||||
|
||||
case .success(let migrationTypes):
|
||||
return true.hashValue
|
||||
^ migrationTypes.map { $0.hashValue }.reduce(0, ^).hashValue
|
||||
|
||||
case .failure(let error):
|
||||
return false.hashValue ^ error.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal init(_ migrationTypes: [MigrationType]) {
|
||||
|
||||
@@ -144,20 +144,23 @@ public enum MigrationType: Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
let preHash = self.hasMigration.hashValue ^ self.isHeavyweightMigration.hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.hasMigration)
|
||||
hasher.combine(self.isHeavyweightMigration)
|
||||
switch self {
|
||||
|
||||
case .none(let version):
|
||||
return preHash ^ version.hashValue
|
||||
hasher.combine(version)
|
||||
|
||||
case .lightweight(let sourceVersion, let destinationVersion):
|
||||
return preHash ^ sourceVersion.hashValue ^ destinationVersion.hashValue
|
||||
hasher.combine(sourceVersion)
|
||||
hasher.combine(destinationVersion)
|
||||
|
||||
case .heavyweight(let sourceVersion, let destinationVersion):
|
||||
return preHash ^ sourceVersion.hashValue ^ destinationVersion.hashValue
|
||||
hasher.combine(sourceVersion)
|
||||
hasher.combine(destinationVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,10 +149,10 @@ public final class ObjectMonitor<D: DynamicObject>: Equatable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return ObjectIdentifier(self).hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(ObjectIdentifier(self))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -132,10 +132,10 @@ public struct OrderBy<D: DynamicObject>: OrderByClause, FetchClause, QueryClause
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return (self.sortDescriptors as NSArray).hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.sortDescriptors)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,39 +44,6 @@ public enum SaveResult: Hashable {
|
||||
}
|
||||
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
public static func == (lhs: SaveResult, rhs: SaveResult) -> Bool {
|
||||
|
||||
switch (lhs, rhs) {
|
||||
|
||||
case (.success(let hasChanges1), .success(let hasChanges2)):
|
||||
return hasChanges1 == hasChanges2
|
||||
|
||||
case (.failure(let error1), .failure(let error2)):
|
||||
return error1 == error2
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
switch self {
|
||||
|
||||
case .success(let hasChanges):
|
||||
return self.boolValue.hashValue ^ hasChanges.hashValue
|
||||
|
||||
case .failure(let error):
|
||||
return self.boolValue.hashValue ^ error.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal init(hasChanges: Bool) {
|
||||
|
||||
@@ -257,19 +257,26 @@ public enum SelectTerm<D: DynamicObject>: ExpressibleByStringLiteral, Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
switch self {
|
||||
|
||||
case ._attribute(let keyPath):
|
||||
return 0 ^ keyPath.hashValue
|
||||
hasher.combine(0)
|
||||
hasher.combine(keyPath)
|
||||
|
||||
case ._aggregate(let function, let keyPath, let alias, let nativeType):
|
||||
return 1 ^ function.hashValue ^ keyPath.hashValue ^ alias.hashValue ^ nativeType.hashValue
|
||||
hasher.combine(1)
|
||||
hasher.combine(function)
|
||||
hasher.combine(keyPath)
|
||||
hasher.combine(alias)
|
||||
hasher.combine(nativeType)
|
||||
|
||||
case ._identity(let alias, let nativeType):
|
||||
return 3 ^ alias.hashValue ^ nativeType.hashValue
|
||||
hasher.combine(2)
|
||||
hasher.combine(alias)
|
||||
hasher.combine(nativeType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -700,10 +707,10 @@ public struct Select<D: DynamicObject, T: SelectResultType>: SelectClause, Hasha
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return self.selectTerms.map { $0.hashValue }.reduce(0, ^)
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.selectTerms)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -105,16 +105,18 @@ public enum SetupResult<T: StorageInterface>: Hashable {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
switch self {
|
||||
|
||||
case .success(let storage):
|
||||
return true.hashValue ^ ObjectIdentifier(storage).hashValue
|
||||
hasher.combine(true)
|
||||
hasher.combine(ObjectIdentifier(storage))
|
||||
|
||||
case .failure(let error):
|
||||
return false.hashValue ^ error.hashValue
|
||||
hasher.combine(false)
|
||||
hasher.combine(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -287,10 +287,10 @@ public struct Where<D: DynamicObject>: WhereClauseType, FetchClause, QueryClause
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return self.predicate.hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.predicate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,11 +75,11 @@ public final class XcodeSchemaMappingProvider: Hashable, SchemaMappingProvider {
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
return self.sourceVersion.hashValue
|
||||
^ self.destinationVersion.hashValue
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
||||
hasher.combine(self.sourceVersion)
|
||||
hasher.combine(self.destinationVersion)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user