Frankie Frankie - 1 year ago 74
Swift Question

Non-exhaustive pattern match for Swift enum

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 {

Answer Source
if [.One, .Two, .Three, .Four].contains(num) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download