title: How to use generics and Any.Type with functions in Swift
body: <p>I'd like to keep a dictionary of keys of Enum Type and values that are managed by the Box type. But when I try to pass the key/value of each element in the dictionary to a function, I keep getting swift compiler errors on type mismatch. </p>
  
  <p>I have Box declared as this:</p>
  
  <pre><code>final class Box&lt;T&gt; {
      let value: T
  
      init(value: T) {
          self.value = value
      }
  }
  </code></pre>
  
  <p>My dictionary:</p>
  
  <pre><code>let dictionary = [Car.Nissan: Box(value: NissanHandler.Type),
                    Car.Honda: Box(value: HondaHandler.Type), 
                    ...]
  </code></pre>
  
  <p>NissanHandler and HondaHandler are both classes which inherit from a protocol named 'AutoHandler'.</p>
  
  <p>As I enumerate through each key/value in the dictionary, I'd like to pass each element off to another function to process it:</p>
  
  <pre><code>Class A {
    func processDictionary() {
      for (key, values) in dictionary {     
          // This line produces the error, 
          // Cannot convert value of type 'Box&lt;CarHandler.Type&gt;' to expected argument type '[Product : Box&lt;Any.Type&gt;]'
          processElement(key, value) 
      }
    }
  
    func processElement(key: Product, value: Box&lt;Any.Type&gt;) {
          // Instantiate the class based on the value's class type
    }    
  }
  </code></pre>
  
  <p>How should I declare my function so I can keep the mapping of the classes that should be instantiated at run time?</p>