title: Why do I get the error “Protocol … can only be used as a generic constraint because it has Self or associated type requirements”?
body: <p>I wrote an extension onto <code>Int</code> as below.</p>
  
  <pre><code>extension Int {
      func squared () -&gt; Int {
          return self * self
      }
  }
  
  print(10.squared()) // works
  </code></pre>
  
  <p>The above code works. Now I want to extend the <code>IntegerType</code> protocol so that Int, UInt, Int64, etc would all conform. My code is as below.</p>
  
  <pre><code>extension IntegerType {
  
      func squared () -&gt; IntegerType { // this line creates error
  
          return self * self
  
      }
  }
  </code></pre>
  
  <p>I get error: </p>
  
  <blockquote>
    <p>Protocol 'IntegerType' can only be used as a generic constraint because it has Self or associated type requirements</p>
  </blockquote>
  
  <p>I already saw <a href="https://stackoverflow.com/questions/24926310/what-does-protocol-can-only-be-used-as-a-generic-constraint-because-it-has">this</a> question and its video &amp; <a href="https://stackoverflow.com/questions/24888560/usage-of-protocols-as-array-types-and-function-parameters-in-swift">this</a> question, still couldn't understand. I only understood that there is some <code>associatedType</code> which in this case is <code>Self</code> but couldn't connect the dots. I feel like also my lack of knowledge on the <code>Generics</code> subject is also a reason...</p>
  
  <p>Can someone elaborate a bit on the subject and why does the extension create an error?</p>