Skip to content

Instantly share code, notes, and snippets.

@Scior
Last active December 18, 2021 07:17
Show Gist options
  • Save Scior/512dabc27fdd7a4efe9bb80c36acdebd to your computer and use it in GitHub Desktop.
Save Scior/512dabc27fdd7a4efe9bb80c36acdebd to your computer and use it in GitHub Desktop.
import Foundation
@propertyWrapper
public struct AlwaysEqual<T> {
public var wrappedValue: T
public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}
}
extension AlwaysEqual: Equatable {
public static func == (lhs: AlwaysEqual<T>, rhs: AlwaysEqual<T>) -> Bool {
return true
}
}
struct Hoge: Equatable {
var id: Int
var name: String
}
let hogeA = Hoge(id: 1, name: "abcd")
let hogeB = Hoge(id: 1, name: "bcde")
let hogeC = Hoge(id: 2, name: "abcd")
print(hogeA == hogeB) // false
print(hogeA == hogeC) // false
struct Fuga: Equatable {
var id: Int
@AlwaysEqual var name: String
}
let fugaA = Fuga(id: 1, name: "abcd")
let fugaB = Fuga(id: 1, name: "bcde")
let fugaC = Fuga(id: 2, name: "abcd")
print(fugaA == fugaB) // true
print(fugaA == fugaC) // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment