Swift Tricks

My own, mostly internal blog of Swift tips and tricks

If/guard case with OR logic

Unfortunately it is not specifically possible to combine `if case` or `guard case` with an OR logic, but you can instead use a creative switch statement:

// Instead of
if case .foo(_) = foo, case .bar = bar OR someVar == true {...}
// (which is invalid syntax)

// Just use:
switch (foo, bar, someVar) {
case (.foo, .bar, _), (_, _, true):