Currently I have a JSON payload with a property mapped to an enum with associated values and custom decoding.
If it weren't for the associated values, I could declare my enum with rawType of String, and this will give me the option to handle "default" cases (not defined cases):
enum Foo: String {
case foo
}
switch foo {
case .foo:
// do something
default:
// handle default case
}
However, because of the associated values, the enum cannot have a rawType of String, and I don't get the benefit of having a "default" case.
enum Bar {
case bar(value: Any)
}
switch bar {
case .bar:
// do something
default: // <------------------------ Not possible :(
// handle default case
}
When decoding JSON, this means the decoding operation will throw an exception if the property contained an unsupported value.
While I can catch and respond to this exception, I'd like to know if there is a way to provide that "default" case. Something like having custom "unfrozen" enums.
Is this possible? Thanks!