Slide 12
Slide 12 text
Synthesized Comparable conformance for enum types SE-0266
12
1/3
// まずComparableとは?
struct Date {
let year: Int
let month: Int
let day: Int
}
extension Date: Comparable {
static func < (lhs: Date, rhs: Date) -> Bool {
if lhs.year != rhs.year {
return lhs.year < rhs.year
} else if lhs.month != rhs.month {
return lhs.month < rhs.month
} else {
return lhs.day < rhs.day
}
}
}
print(Date(year: 10, month: 10, day: 10) > Date(year: 10, month: 10, day: 9)) // true