title: Error why matching an enumeration using a if statement
body: <p>I face a problem using enumeration I can't understand.</p>
  
  <p>Here is declaration of an enumeration type:</p>
  
  <pre><code>enum SomeType {
      case un
      case deux
      case trois
  }
  </code></pre>
  
  <p>Then I want to match an individual enumeration values with a <code>if</code> statement:</p>
  
  <pre><code>var testValue: SomeType = .trois
  
  if testValue == .trois {
      // Do something
  }
  </code></pre>
  
  <p>Everything is fine!</p>
  
  <p>Now I want to add an <em>associated value</em> only to the first <em>member value</em>:</p>
  
  <pre><code>enum SomeType {
      case un(Int)
      case deux
      case trois
  }
  
  var testValue: SomeType = .trois
  
  if testValue == .trois {
      // Do something
  }
  </code></pre>
  
  <p>An error than appear on the <code>if</code> statement: <code>Could not find member 'trois'</code></p>
  
  <p>Does this mean enumerations can only be matched using a <code>switch</code>statement?</p>
  
  <p><strong>Precisions</strong><br>
  What I want to achieve is: "Does testValue is of member value of 'trois' with no consideration for associated value". In others words, how to match an enumeration on member value only.</p>
  
  <p>Here a solution implementing <a href="https://stackoverflow.com/users/3925941/airspeed-velocity">Airspeed Velocity</a> answers:</p>
  
  <pre><code>// Test equality only on member value
  func == (lhs:SomeType, rhs:SomeType) -&gt; Bool {
      switch (lhs, rhs) {
      case (.un(let lhsNum), .un(let rhsNum)):return true
      case (.deux, .deux): return true
      case (.trois, .trois): return true
      default: return false
      }
  }
  
  // Test equality on member value AND associated value
  func === (lhs:SomeType, rhs:SomeType) -&gt; Bool {
      switch (lhs, rhs) {
      case (.un(let lhsNum), .un(let rhsNum)) where lhsNum == rhsNum: return true
      case (.deux, .deux): return true
      case (.trois, .trois): return true
      default: return false
      }
  }
  
  var testValue = SomeType.un(3)
  
  
  // Tests
  
  if testValue == .un(1) {
      println("Same member value")
  }
  
  
  if testValue === .un(3) {
      println("Same member value AND same associated contents")
  }
  </code></pre>