title: Dynamically initialize enum based on associated value
body: <p>This is my enum:</p>
  
  <pre><code>enum E {
      case a(Int), b(String)
  }
  </code></pre>
  
  <p><strong>The enum's associated value types are unique and always exactly one.</strong></p>
  
  <p>Let's say I have this variable:</p>
  
  <pre><code>let myInt = 0
  </code></pre>
  
  <p>I want to create an instance of <code>E</code>, based on variable <code>myInt</code>, <strong>dynamically</strong>. This should result in:</p>
  
  <pre><code>E.a(0)
  </code></pre>
  
  <p>But in the 'real world', I don't know what property I get. I only know one thing: I can initialize enum <code>E</code> with it. I need to dynamically initialize the enum, based on a property value. I currently have a huge switch on the property to initialize the enum, I don't want that.</p>
  
  <p>But I have no idea how to accomplish this task. I tried mirroring the enum type, but I get a complex type and I have no idea how to proceed initializing it even if I know the types.</p>
  
  <p>So I get a property of a certain type. I know that certain type matches a case in enum E, because there is exactly one case which associated value corresponds to the property type. I want to initialize an instance of that enum with that case, with the value of the property.</p>