Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum cases with associated values cannot be marked potentially unavailable with '@available'

I am getting an error message with Xcode 13 on the following code

@available(iOS 13.0, *)
    case windowScene(_: UIWindowScene, windowLevel: UIWindow.Level)

Enum cases with associated values cannot be marked potentially unavailable with '@available'

Does anyone know why I'm getting this error and what is the solution to rectify it? It was working fine in Xcode 12.

like image 781
Hassy Avatar asked Aug 12 '21 08:08

Hassy


1 Answers

See this Swift bug for an explanation and workaround from the Swift compiler team.

This is intentional. The ABI of enum cases with payloads that are potentially unavailable is not well-defined. That this worked in the past was by coincidence of your application not requiring the (potentially unavailable) type metadata for the payload. Please either increase your deployment target or mark Foo itself as available as the least-available case. https://github.com/apple/swift/pull/36327

So you either need to mark the whole enum as @available(iOS 13.0, *) or need to increase your deployment target to iOS 13.0.

like image 149
Dávid Pásztor Avatar answered Sep 24 '22 00:09

Dávid Pásztor