2

How can I negate pattern matching in Swift?

For example I want to do something like:

guard case .wait != currentAction.type else {
    return
}

But apparently, I can't. I can do this:

    if case .wait = currentAction.type {
        return
    }

but it's less Swifty. Is there a better way?

Alexander
  • 59,041
  • 12
  • 98
  • 151
s1ddok
  • 4,615
  • 1
  • 18
  • 31
  • You cannot negate a pattern, compare http://stackoverflow.com/questions/37926509/complementery-of-an-if-case. – Martin R Jun 24 '16 at 16:01

2 Answers2

1

Apparently, there is no way to do that right now as of Swift 3.

Things can change in future releases.

s1ddok
  • 4,615
  • 1
  • 18
  • 31
1

You can do this in Swift 3.0.2:

guard currentAction.type != .wait else {
    return
}
kareman
  • 711
  • 1
  • 6
  • 16