Skip to content

Instantly share code, notes, and snippets.

@karambirov
Created October 17, 2022 08:57
Show Gist options
  • Save karambirov/7824a453686e329dd7927d5656a4b624 to your computer and use it in GitHub Desktop.
Save karambirov/7824a453686e329dd7927d5656a4b624 to your computer and use it in GitHub Desktop.
Allows to ignore properties that prevent auto-conforming to Hashable
private let hashableId = UUID()
@propertyWrapper
public struct IgnoreHashable<T>: Hashable {
public let wrappedValue: T
public init(wrappedValue: T) {
if wrappedValue is AnyHashable {
AssertionFailure("Hashable types shouldn't ignore its hash value")
}
self.wrappedValue = wrappedValue
}
public func hash(into hasher: inout Hasher) {
hasher.combine(hashableId)
}
public static func == (lhs: Self, rhs: Self) -> Bool {
return true
}
}
@propertyWrapper
public struct IgnoreEquatable<T>: Equatable {
public let wrappedValue: T
public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
public static func == (lhs: Self, rhs: Self) -> Bool {
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment