I can't seem to write down the label of a String.
I have an enum with an associated value, as shown here:
public enum HTTPMethod {
case get
case post(body: [String: Any])
case put
case delete
case patch
}
I can print the value
let get = HTTPMethod.get
print (get) // get
but what I actually want is the name of the enum, in an uppercase version.
i.e. get would be GET
I'm trying to write an extension for just this:
extension HTTPMethod: CustomStringConvertible {
public var description: String {
return String(describing: self)
}
}
Doesn't work also
extension HTTPMethod: CustomStringConvertible {
public var description: String {
return String(describing: self)
}
}
A version with reflection also doesn't work in my implementation:
extension HTTPMethod: CustomStringConvertible {
public var description: String {
let mirror = Mirror(reflecting: self)
return (mirror.children.first?.label)!
}
}
So how can I write the uppercase label of the enum?