I have the following enum in Swift:
enum Animal {
case Cat(name: String, color: String)
case Dog(name: String, tailLength: Double)
case Cow(name: String, isBrown: Bool)
}
Is there a way to get the name of an Animal without a switch that matches each case one by one? Something like:
func animalName(a: Animal) -> String {
// This does not work, you have to use a switch
return a.name
}