enum E: CaseIterable { case a }
E.allCases.forEach {
print($0)
}
is rewritten to
enum E: CaseIterable { case a }
for cas in E.allCases {
print(cas)
}
which is valid. Yet, the chosen identifier cas comes a bit surprising. It's clear that identifier names can only be derived heuristically and case is a keyword in Swift that cannot be used. The allCases list is so common, though, that I suggest to use some real name instead like one of the defaults element, item or value. Other option: Use a quoted `case`.
The example
is rewritten to
which is valid. Yet, the chosen identifier
cas
comes a bit surprising. It's clear that identifier names can only be derived heuristically andcase
is a keyword in Swift that cannot be used. TheallCases
list is so common, though, that I suggest to use some real name instead like one of the defaultselement
,item
orvalue
. Other option: Use a quoted`case`
.