title: Accessing Associated Values in an Array of Swift Enum in an Opaque Fashion
body: <p>I haven't really found what I need in the associated questions. That may be because I'm a bit thick, and didn't see it, but here's my quandary:</p>
  
  <p>I have a computed property that returns an Array of enums with associated values.</p>
  
  <p>The values are all the same types (in my use case, the type is a "flag"), but the enums are different.</p>
  
  <p>I'd like to see if there was some way to cycle through the Array, looking at only the associated values, regardless of the enum type. I am attaching a small playground that shows what I mean:</p>
  
  <pre><code>enum A {
      case valueA(Int)
      case valueB(Int)
      case valueC(Int)
  }
  
  let a: [A] = [.valueA(0), .valueB(1), .valueC(2)]
  
  for each in a {
      print(String(describing: each))
  }
  
  print();
  
  // This works:
  
  for each in a {
      if case let .valueA(value) = each {
          print(value)
      }
      if case let .valueB(value) = each {
          print(value)
      }
      if case let .valueC(value) = each {
          print(value)
      }
  }
  
  print();
  
  // So does this:
  
  for each in a {
      var value: Int = 0
  
      switch each {
      case .valueA(let val):
          value = val
  
      case .valueB(let val):
          value = val
  
      case .valueC(let val):
          value = val
      }
  
      print(value)
  }
  
  // What I want:
  
  //for each in a {
  //    if case let A(value) = each {
  //        print(value)
  //    }
  //}
  </code></pre>
  
  <p>I want to be able to treat each member of the collection, and extract its flag, and then make a decision, based on that flag.</p>
  
  <p>I know that I could do it with a big ol' switch statement, with all the enum values (second go), but it would be nice if there were some generic way to just access all the values.</p>