title: Generic function in Swift
body: <p>I am from C++ and I'm a little confused about generic function in Swift.</p>
  
  <p>In C++, I can do that :</p>
  
  <pre><code>class Entity
  {
      template    &lt;typename T&gt;
      T *getComponent()
      {
          return (T *)(listComponent_[typeid(T).name()]);
      }
  };
  </code></pre>
  
  <p>and I can do this to get a specific <code>Component</code> from my <code>Entity</code></p>
  
  <pre><code>Entity().getComponent&lt;LifeComponent&gt;();
  </code></pre>
  
  <p>I would like to reproduce this in Swift, but I can't figure out how to achieved it.</p>
  
  <p>In Swift, I have to defined a parameter to my function to determine my type.</p>
  
  <p>In Swift :</p>
  
  <pre><code>class Entity
  {
      func get&lt;T&gt;() -&gt; T
      {
           return ??
      }
  }
  </code></pre>
  
  <p>I would like to be able to do :</p>
  
  <pre><code>Entity().get&lt;LifeComponent&gt;()
  </code></pre>
  
  <p>Can you help me ?</p>