I have a function that returns the specific Unicode.Unicodec interface, as follows:
static func encodingStrToDecoder(_ encoding: String) -> some UnicodeCodec {
switch encoding {
case Encoding.utf8:
print("Returning UTF8")
return UTF8()
case Encoding.utf16:
print("Returning UTF16")
return UTF16()
case Encoding.utf32:
print("Returning UTF32")
return UTF32()
default:
print("Returning UTF8 (DEFAULT)")
return UTF8()
}
}
Encoding.utf8 and such are just String constants.
However, I get a
Function declares an opaque return type, but the return statements in its body do not have matching underlying types
error. What am I doing wrong?