I think I understand the logic behind @unknown default, and I apologize for screenshots instead of code, but it's the only way to see the error messages in context.
Converted a project to Swift 5. It runs, but gets this warning, which I understand:
So I let Xcode fix it for me, and got this:
I changed the order of the stub cases (this is a work in progress), which makes the compiler happy again:
Am I doing something I shouldn't, or is this weird compiler behavior?
The error in the middle image looks like a bug in swift and it could be solved by adding a semicolon at the end of the return statement.
In general the compiler is expecting @unknown default
to be the last case. Check @unknown documentation from apple where they explain why it must be used with the last case in a switch and more on the "unknown patterns" link in the following quote:
@unknown may only be applied to default or a case consisting of the single pattern _. Even in the latter case, @unknown must be used with the last case in a switch. This restriction is discussed further in the "unknown patterns" section under "Future directions".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With