title: Passing self as argument to a Protocol function that wants same type as self as the argument
body: <p>I'm writing an async dictionary that returns a Future with the value: </p>
  
  <ul>
  <li>immediately if it's already cached, or</li>
  <li>after the (network) operation if it isn't yet</li>
  </ul>
  
  <p>The dictionary inside my class is generic, so the class is as well. Currently the user has to read the docs and know to set the <code>dataCall</code> function, which is how the dictionary knows how to get a value for a key, in the form</p>
  
  <pre><code>var dataCall: ((key: Key) -&gt; Future&lt;Value, MyError&gt;)?
  </code></pre>
  
  <p>But this requires other programmers to know about the data call and set it.
  So I wrote a protocol</p>
  
  <pre><code>protocol CacheDelegate {
      typealias T: Hashable
      typealias U
      func dataCallForCacheManager(cacheManager: CacheManager&lt;T, U&gt;) → (key: T) → Future&lt;Value, MyError&gt;
  }
  </code></pre>
  
  <p>However, then if I try and call this in <code>init()</code> as</p>
  
  <p><code>delegate.dataCallForCacheManager(self)</code></p>
  
  <p>I get the error </p>
  
  <blockquote>
    <p>Cannot invoke <code>dataCallForDictionary</code> with an argument list of type '(CacheManager)'</p>
  </blockquote>
  
  <p>I also cannot make a <code>var delegate: CacheDelegate?</code> because</p>
  
  <blockquote>
    <p>Protocol <code>CacheDelegate</code> can only be used as a generic constraint because it has Self or associated type requirements.</p>
  </blockquote>
  
  <p>So I find myself in a pickle where I can't pass myself as an argument, and I can't set a delegate to get my data call from this protocol. Am I missing something? I'm willing to do Swift 2 Voodoo. </p>
  
  <p>The contents of a toy example (without Futures and the dictionary and everything) is below:</p>
  
  <pre><code>import Foundation
  
  protocol Delegate {
      typealias T: Hashable
      typealias U
      func dataCallForDictionary(dictionary: MyDictionary&lt;T, U&gt;) -&gt; (T) -&gt; (U)
  }
  
  struct MyDictionary&lt;Key: Hashable, Value&gt; {
      typealias T = Key
      typealias U = Value
  
      init&lt;Object: Delegate&gt;(delegate: Object) {
          dataCall = delegate.dataCallForDictionary(self)
  //        self.delegate = delegate
      }
  
      var delegate: Delegate?
  
      var dataCall: ((key: Key) -&gt; Value)?
  }
  </code></pre>