title: How do I know the type of an enum with associated value in a generic way?
body: <p>A few days ago, I have asked <a href="https://stackoverflow.com/questions/65843409/how-do-i-solve-this-mixed-enum-equatable-thing">this question</a>.</p>
  <p>The brilliant solution was like this:</p>
  <pre><code>enum MyEnum {
      case one
      case two
      case three(user: String)
   
      func isOfSameType(_ other: MyEnum) -&gt; Bool {
          switch (self, other) {
          case (.one, .one):
              return true
          case (.two, .two):
              return true
          case (.three, .three):
              return true
          default:
              return false
          }
      }
  }
   
  var array: [MyEnum] = []
  func add(_ value: MyEnum) {
      if array.contains(where: { value.isOfSameType($0) }) { return }
      array.append(value)
  }
  </code></pre>
  <p>Now, analyzing that with cold blood, this seems to be completely black magic.</p>
  <p>How can the switch compare things without parameters?</p>
  <p>But now I need to check if the last element on <code>stack</code> is of kind <code>three</code>.</p>
  <p>Something like</p>
  <pre><code>if array!.last.isOfType(.three) {
  }
  </code></pre>
  <p>This will not work. Xcode will require paremeters from .three.</p>
  <p>Because I am not understanding what I have so far, I cannot figure out how to do that.</p>