Given the following enum:
enum Labels: String {
case foo
case bar
case baz
@available(iOS 14, *)
case notAvailableYet
}
With the following code:
@avaliable(iOS14, *)
fun foo() {
}
switch label {
case . notAvailableYet:
foo()
}
The compiler will force you to wrap the call-site for foo()
with a availability check even that case is already for an enum which is marked as only being available for the same iOS version.
It would be great if the compile could automatically synthesise this availability check as part of the case statement so it won't execute that case (If rawValue was used to dynamically select that enum then perhaps there could be a runtimes error)
Otherwise if this isn't possible for reasons of explicitness then it would be great to have some syntax sugar to clean up the code
So this:
switch label {
case . notAvailableYet:
if #avaliable(iOS 14, *) {
foo()
}
}
Can become something like this:
switch label {
@avaliable(iOS14, *)
case . notAvailableYet:
foo()
}