WWDC24 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: Checking switch cases twice does not create an issue

Forums > 100 Days of SwiftUI


In tutorial it is described as:

If you try changing .snow for .rain, you’ll see Swift complains loudly: once that we’ve checked .rain twice

I check the rainy case twice in switch case and it does not produce any error

enum Weather {
    case rainy
    case snowy
    case sunny

let test = Weather.sunny

switch test {
    case .rainy:
    case .snowy:
    case .sunny:
    case .rainy:

Why is that?


I check the rainy case twice in switch case and it does not produce any error.

I pasted your code into Playgrounds and you're right, it doesn't produce an error. But, for me, it did produce a warning on the second .rainy case.

⚠️ Case is already handled by previous patterns; consider removing it.


Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.