Enum with a description

Hi all, I would like to use Enum with a raw value and a short description e.g.

enum DayOfTheWeek: String, CaseIterable, Identifiable{
var id: String {self.rawValue}
case monday = "Monday"
case tuesday = "Tuesday"

for each day, I need to add short description, as a separate Text, e.g.:

case monday = "Monday" var description = "it's a great day to have a coffee"

I would like to be able to use for a Text field etc. is it possible or I am on the wrong track? I was thinking of an array or dictionary and make a reference to each element, but I think there must be a better way?

Answered by Dove Zachary in 740894022

Just try

enum DayOfTheWeek: String, CaseIterable, Identifiable{
    var id: String {self.rawValue}
    case monday = "Monday"
    case tuesday = "Tuesday"
    
    var description: String {
        switch self {
        case .monday:
            return "it's a great day to have a coffee"
        case .tuesday:
            return "..."
        }
    }
}
// it's a great day to have a coffee
let mondayDescription: String = DayOfTheWeek.monday.description
Accepted Answer

Just try

enum DayOfTheWeek: String, CaseIterable, Identifiable{
    var id: String {self.rawValue}
    case monday = "Monday"
    case tuesday = "Tuesday"
    
    var description: String {
        switch self {
        case .monday:
            return "it's a great day to have a coffee"
        case .tuesday:
            return "..."
        }
    }
}
// it's a great day to have a coffee
let mondayDescription: String = DayOfTheWeek.monday.description

exactly what I was looking for, thank you very much. Happy New Year 🎉

Enum with a description
 
 
Q