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

5

11

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.

Semiprofessional answered 12/8, 2021 at 8:17 Comment(0)
S
12

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.

Scarab answered 12/8, 2021 at 8:49 Comment(1)
now it is marked as resolved, but in Xcode 13.0 (13A233) I still have itTriton
B
6

I got the same message while I was using the pod 'SwiftMessages' for showing the pop-up message.

I just replaced pod 'SwiftMessages' to pod 'SwiftMessages', '~> 5.0'.

Bushman answered 4/11, 2021 at 13:6 Comment(0)
N
3

It is listed on the release notes for Xcode 13 Beta 3 that it was a bug in the compiler that allowed this to occur.

This is an excerpt:

The compiler used to erroneously accept @available annotations on enum cases with associated values that were newer than the deployment target. (80238318)

For example:

@available(macOS 12, *)
public struct Crayon {}

public enum Pen {
  case pencil

  @available(macOS 12, *)
  case crayon(Crayon)
}

While this worked in some cases, there was no way for the Swift runtime to perform the requisite dynamic layout needed in general, so this could cause crashes at runtime. The compiler now rejects such availability newer than the deployment target on enum cases.


So although you could do it before, you cannot do it now as the compiler cannot perform the checks that it required.

Either you can mark the whole enum as @available. But a solution, without knowing the full context may be difficult to come by.

Nook answered 12/8, 2021 at 8:52 Comment(0)
P
2

Just update your pods. I think you are using some pods which are outdated for Xcode 13. For example, a pod called SwiftMessages has this kind of issue. After, pod update, that problem is solved for me. I hope, it will help you.

Periotic answered 12/10, 2021 at 12:3 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Effluent
L
0

I solved it by commenting out the syntax @available(iOS 13.0, *) which was the error Enum cases with associated values cannot be marked potentially unavailable with '@available'.

error was Swift Compiler Error and in NowPlayingInfoProperty.swift file which was two Error code.

original code like:

@available(iOS 13.0, *)
case serviceIdentifier(String?)
...

to changed code like:

//@available(iOS 13.0, *)
case serviceIdentifier(String?)
...
Lamee answered 19/8, 2022 at 2:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.