Last active
December 18, 2021 07:17
-
-
Save Scior/512dabc27fdd7a4efe9bb80c36acdebd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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