Swift - Comparable
2022-03-26 本文已影响0人
aven_kang
class Student : Comparable {
static func < (lhs: Student, rhs: Student) -> Bool {
lhs.score < rhs.score
}
static func > (lhs: Student, rhs: Student) -> Bool {
lhs.score > rhs.score
}
static func == (lhs: Student, rhs: Student) -> Bool {
lhs.score == rhs.score
}
static func <= (lhs: Student, rhs: Student) -> Bool {
!(lhs > rhs)
}
static func >= (lhs: Student, rhs: Student) -> Bool {
!(lhs < rhs)
}
var score: Int
var age:Int
init(age:Int,score:Int) {
self.age = age
self.score = score
}
}