Yeah, for what it's worth, using our case paths library your first situation can be expressed like so:
import CasePaths
@CasePathable
@dynamicMemberLookup
enum MyEnum {
case first(data: String)
case second(data: String)
case third(data: [String])
case fourth
case fifth
case sixth
}
let value1 = MyEnum.first(data: "Gabriel")
let value2 = MyEnum.second(data: "Aurora")
var value3 = MyEnum.third(data: ["Gabriel", "Aurora", "Marcela"])
if let data = value1.first ?? value2.second {
print(data)
}
And your second situation like this:
if
let data1 = value1.first,
let data2 = value2.second,
let data3 = value3.third
{
print(data1)
print(data2)
print(data3)
}
And there are a few other niceties too, such as an expression version of case
pattern matching:
if value1.is(\.first) {
// ...
}
Of course, this is only viable if you are OK depending on a 3rd party library and OK with the cost of macros.