title: Implement delegate using generic protocol in Swift
body: <p>I'm trying to create a delegate protocol that implements a function which passes an array of a generic type. I've tried several combinations but none of them seem to do the trick.</p>
  
  <p>This is the most approximate thing i've reached to. This is the protocol:</p>
  
  <pre><code>     protocol APIControllerProtocol {
  
            typealias T
  
            func didReceiveAPIResults(results: [T])
       }
  </code></pre>
  
  <p>And this is the the delegator object:</p>
  
  <pre><code>    class APIController&lt;U:APIControllerProtocol&gt; {
  
           typealias ElementType = U
           var delegate: ElementType?
  
           init(delegate: ElementType){
  
               self.delegate = delegate
  
           }
  
           func getAPIResults(){
  
                // Perform some action before delegation
                // "results" is an Array of dictionaries got from NSJSONSerialization
  
                self.delegate?.didReceiveAPIResults(results.map{dict in Album(json:dict)})
  
           }
  
       }
  </code></pre>
  
  <p>However, the last line get this error: "Album is not convertible to U.T"</p>
  
  <p>"Album" is the model object used to return the results. </p>
  
  <p>What am i doing wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Following <a href="https://stackoverflow.com/questions/25732775/implement-delegate-using-generic-protocol-in-swift/25734549#25734549">Mike S advice</a>, i've made the protocol method <code>didReceiveAPIResults</code> a generic function, and specified what <code>T</code> is in the delegate. However, when receiving and assigning the argument of type T to a property in the delegate, i get the error: "T is not identical to T"</p>
  
  <pre><code>class TestDelegate: APIControllerProtocol {
      typealias T = Album
      var albums:[T] = [T]()
  
      func didReceiveAPIResults&lt;T&gt;(results: [T]) {
          // ...
  
          self.albums = results //ERROR: "T is not identical to T"
      }
  }
  </code></pre>