Hugo Alonso
Hugo Alonso

Reputation: 6824

How to prettify enum with arguments comparison in Swift?

This is what I have

let kind = //This returns one of the cases with it corresponding arguments

if kind == .didChangeValue(value: nil) {
             //my Stuff
}

this is what I want:

if kind == .didChangeValue {
                 //my Stuff
}

Notice that:

This is happening because my enum has arguments, I already implemented how they should compare with each other and the value has no value to me.

So, I'm trying to get it to look more swifty and less like a RAW HACK

Upvotes: 1

Views: 61

Answers (1)

Martin R
Martin R

Reputation: 539995

You can check an enumeration value with pattern matching:

if case .didChangeValue = kind {
    // ...
}

Upvotes: 2

Related Questions