โญComparable Enums

Swift โŸฉ enum โŸฉ

Swift 5.3 ๐Ÿ‘‰ SE0266

๐Ÿ’พ ็จ‹ๅผ๏ผšpaiza.io

// โญ Comparable Enums (Swift 5.3)
//   compare according to declaration order (earlier < later)
enum Color: Comparable {
    case blue
    case green
    case white(Double)  // โญ associated values must be `Comparable`
    case red
    case black
}

let colors: [Color] = [
    .blue, .black, .red, .white(0.7), .white(0.3), .red
]

print(colors.sorted())
// [.blue, .white(0.3), .white(0.7), .red, .red, .black]

Last updated