title: enums with Associated Values + generics + protocol with associatedtype
body: <p>I'm trying to make my API Service as generic as possible:</p>
  
  <p><strong>API Service Class</strong></p>
  
  <pre><code>class ApiService {
    func send&lt;T&gt;(request: RestRequest) -&gt; T {
      return request.parse()
    }
  }
  </code></pre>
  
  <p>So that the compiler can infer the response type from the request categories <code>.auth</code> and <code>.data</code>:</p>
  
  <pre><code>let apiService = ApiService()
  
  // String
  let stringResponse = apiService.send(request: .auth(.signupWithFacebook(token: "9999999999999")))
  // Int
  let intResponse = apiService.send(request: .data(.content(id: "123")))
  </code></pre>
  
  <p>I tried to come up with a solution using generics and a protocol with associated type to handle the parsing in a clean way. However I'm having trouble associating the request cases with the different response types in a way that it's simple and type-safe:</p>
  
  <pre><code>protocol Parseable {
    associatedtype ResponseType
    func parse() -&gt; ResponseType
  }
  </code></pre>
  
  <p><strong>Endpoints</strong></p>
  
  <pre><code>enum RestRequest {
  
    case auth(_ request: AuthRequest)
    case data(_ request: DataRequest)
  
    // COMPILER ERROR HERE: Generic parameter 'T' is not used in function signature
    func parse&lt;T: Parseable&gt;() -&gt; T.ResponseType {
      switch self {
      case .auth(let request): return (request as T).parse()
      case .data(let request): return (request as T).parse()
      }
    }
  
    enum AuthRequest: Parseable {
      case login(email: String, password: String)
      case signupWithFacebook(token: String)
  
      typealias ResponseType = String
      func parse() -&gt; ResponseType {
          return "String!!!"
      }
    }
    enum DataRequest: Parseable {
      case content(id: String?)
      case package(id: String?)
  
      typealias ResponseType = Int
      func parse() -&gt; ResponseType {
          return 16
      }
    }
  }
  </code></pre>
  
  <p>How is <code>T</code> not used in function signature even though I'm using <code>T.ResponseType</code> as function return?</p>
  
  <p>Is there a better still clean way to achieve this?</p>