Please note that I read this post , but this post uses the expression switch and it should do something (returns true) when it matches the pattern. I, on the other hand, do not want to do anything if the template matches and uses the if-case statement.
I have this listing:
enum MyEnum { case a case b(Int) case c case d }
Here is an example:
let myEnum: MyEnum = .a
Now I want to do something if myEnum not .b . Since .b has a related meaning, I can't just use the if if check:
if myEnum != .b { // compiler error // do my thing here }
Therefore, I have to use the if-case statement to match the pattern:
if case .b(_) = myEnum { } else { // do my thing here }
But I really hate using the empty if clause. It just looks unattractive to me. I tried to naively do this:
if case .b(_) != myEnum { // compiler error! // do my thing here }
Is there a better way to do this otherwise than using an empty if clause?
I still have code that should run regardless of whether the pattern matches, so the guard statement doesn't work.
source share