struct ExampleStruct1: Equatable {
var exampleValue1: Int = 0
var exampleValue2: Int = 0
}
func == (lhs: ExampleStruct1, rhs: ExampleStruct1) -> Bool {
return (lhs.exampleValue1 == rhs.exampleValue1 && lhs.exampleValue2 == rhs.exampleValue2)
}
let testEquatable1 = ExampleStruct1(exampleValue1: 10, exampleValue2: 20)
let testEquatable2 = ExampleStruct1(exampleValue1: 20, exampleValue2: 40)
let testEquatable3 = ExampleStruct1(exampleValue1: 10, exampleValue2: 20)
testEquatable1 == testEquatable2 // false
testEquatable1 == testEquatable3 // true
struct ExampleStruct2: Equatable, Comparable {
var value: Int = 0
}
func < (lhs: ExampleStruct2, rhs: ExampleStruct2) -> Bool {
return lhs.value < rhs.value
}
func == (lhs: ExampleStruct2, rhs: ExampleStruct2) -> Bool {
return lhs.value == rhs.value
}
let testComparable1 = ExampleStruct2(value: 10)
let testComparable2 = ExampleStruct2(value: 20)
let testComparable3 = ExampleStruct2(value: 10)
testComparable1 < testComparable2 // T
testComparable1 > testComparable2 // F
testComparable1 < testComparable3 // F
testComparable1 > testComparable3 // F
testComparable2 < testComparable3 // F
testComparable2 > testComparable3 // T
testComparable1 == testComparable3 // T