I have an enum like this
enum Public
{
case IHDR,
PLTE,
IDAT,
IEND,
cHRM,
gAMA,
iCCP,
sBIT,
sRGB,
bKGD,
hIST,
tRNS,
pHYs,
sPLT,
tIME,
iTXt,
tEXt,
zTXt
init?(_ a:UInt8, _ p:UInt8, _ r:UInt8, _ c:UInt8)
{
switch (a, p, r, c)
{
case (73, 72, 68, 82):
self = .IHDR
case (80, 76, 84, 69):
self = .PLTE
case (73, 68, 65, 84):
self = .IDAT
// ...
default:
return nil
}
}
var rawValue:(UInt8, UInt8, UInt8, UInt8)
{
switch self
{
case .IHDR:
return (73, 72, 68, 82)
case .PLTE:
return (80, 76, 84, 69)
case .IDAT:
return (73, 68, 65, 84)
// ...
}
}
}
The “raw values” are too complex to be actual raw values, but there’s still a 1–1 relationship between enum cases and expanded representations. Repeating all the constants in the initializer and raw value property is verbose and error-prone. Should there be sugar for this kind of enum, preferably similar to our existing raw value enums?