我有一个带有关联值的枚举。此外,每个值都有一个字符串描述。我怎样才能得到所有案例的描述?
enum MyEnum {
case caseA(data: [DataOfTypeA])
case caseB(data: [DataOfTypeB])
case caseC(data: [DataOfTypeC])
case caseD(data: [DataOfTypeD])
var typeDescription: String {
switch self {
case .caseA:
return "caseA"
case .caseB:
return "caseB"
case .caseC:
return "caseC"
case .caseD:
return "caseD"
}
}
}
我正在寻找的是:
"caseA, caseB, caseC, caseD"