Comparable使えば良いよ
public enum Emoji: String, Comparable {
case neko = "😺"
case inu = "🐶"
case usi = "🐮"
var priority: Int {
switch self {
case .neko:
return 0
case .inu:
return 1
case .usi:
return 2
}
}
public static func <(_ lhs: Emoji, _ rhs: Emoji) -> Bool {
return lhs.priority < rhs.priority
}
}
let emojis: [Emoji] = [.neko, .inu, .usi, .inu]
let topPriorityEmoji = emojis.max()
topPriorityEmoji?.rawValue //"🐮"
Comparable使えば別にStringでなくてもいいし、enumでなくてもよい