It did not. Infinite recursion. Thought so. But Swift often surprises me (which is not necessarily a bragging right imo).
If it were an super/sub type relationship, I'd call the "super" version. But I'm not sure how to get the "default stringification of an enum" in the my false branch, so that I can tune it for just the one distinct value.
In fact, by convention, enum cases should begin with lowercase letters, therefore, the normal way of implementing CustomStringConvertible would be…
enum UnitCode : UInt
{
case unknown = 0
case hz = 1
case gpm = 2
case m3_Hour = 3
case mA = 4
case psi = 5
case bar = 6
}
extension UnitCode : CustomStringConvertible
{
var description: String
{
switch self
{
case .unknown:
return "Unknown"
case .hz:
return "Hz"
case .gpm:
return "GPM"
case .m3_Hour:
return "m³/hr"
case .mA:
return "mA"
case .psi:
return "PSI"
case .bar:
return "Bar"
}
}
}
Fair enough... but is there no way to get the "default" implementation that is used to convert enums to strings so that it can be "customized/extended" in the description implementation. Let's say that they're all defined lowercase, but for some reason, I want to do a description that is "default description as uppercase". Of course I can just add another method that does that. But my real question is how I call the "base" algorithm.
The only "base algorithm" is to literally "stringify" the enum case names. That is the reason why you need to implement CustomStringConvertible - which is an all or nothing affair.