I want to match against multiple enums and have something like this:
guard case .north = $0, case .south = $0 else { return }
Is there a way to condense this to a single statement like this?
guard case (. north, . south) = $0 else { return }
The above does not compile, but was hoping I can do something like this. Is there an alternative?
You can put the desired cases into a literal array and use contains
to test for a match:
guard [.north, .south].contains($0) else { return }
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