title: Associated type in protocol extension
body: <p>I want to create a protocol and extension which I will use in three different view controllers for API loading.</p>
  
  <pre><code>protocol WebAPILoader {
  
      // URL of remote resource
      var url: URL? { get set }
  
      // Array supposed to store loaded data.    
      associatedtype T
      var data: [T] { get set }
  
      // Function loading them
      func loadNextPage()
  }
  </code></pre>
  
  <p>Every VC downloads different data using its endpoint so I want my function to choose which endpoint to use based on data type, like this:</p>
  
  <pre><code>extension WebAPILoader {
  
      mutating func loadNextPage() {
  
          guard let url = self.nextURL else {
              return
          }
  
          let dataType = type(of: data)
          var endpointLoader: ((URL?, @escaping (dataType? ,URL?, Error?) -&gt; Void) -&gt; ())? = nil
  
          switch data {
          case is [DataType1]:
              endpointLoader = DataType1().getData
  
          // Other cases...
  
          default:
              return
          }
  
  
          // EndpointLoader usage...
      } 
  }
  </code></pre>
  
  <p>But Xcode keeps telling me various errors forbidding me from use of T as a Type in my extension. Is there any way of achieving that?</p>