Frankie Frankie - 3 months ago 7x
iOS Question

Swift: if case pattern match for multiple OR conditions

Trying to come up with a Swifty way to do this...

I have an enum I want to execute code only for certain cases and do nothing all other times (non-exhaustive)

This seems overly verbose for Swift

if num == .One || num == .Two || num == .Three || num == .Four {

This leaves me with a default case where I want to do nothing but still have to add something like a

switch num {
case .One, .Two. Three, .Four:
print("do nothing but I still need to put something here")

I would like to do something like this... does it exist in Swift?

if case .One, .Two, .Three, .Four == num {

If [.One, .Two, .Three, .Four].contains(num) {