Swift generics: "Generic parameter T could not be inferred"
<p>I'm trying to make a generic request handler class based on Moya and Object Mapper.
Basically I want a method that performs a request to a Moya Target and performs some basic handling on both sucess and failure cases:</p>

<p>my class would be something like this based on <a href="https://stackoverflow.com/questions/37061033/generic-parameter-t-could-not-be-inferred-factory-methods">this answer</a>:</p>

<pre><code>class APIRequestHandler&lt;T: Mappable&gt; {
  let provider = APIManager().getAPIProvider() // Moya provider

  func performRequest(target: Target, completionHandler: (response: T?, error: StoreError?) -&gt; Void) {
    provider.request(target) { result in
      switch result {
      case let .Success(response):
        switch response.statusCode {
        case 200..&lt;300:
          do {
            let json = try NSJSONSerialization.JSONObjectWithData(response.data, options: .MutableContainers)
            let contractualDocument = Mapper&lt;T&gt;().map(json)
            completionHandler(response: contractualDocument!, error: nil)
          } catch _ {
            // Unexpected error when the response can't be parsed
            completionHandler(response: nil, error: StoreError.UnexpectedError)
          }
        case 500:
          completionHandler(response: nil, error: StoreError.ServerError)
        default:
          completionHandler(response: nil, error: StoreError.HTTPError(statusCode: response.statusCode))
        }
      case .Failure(_):
        completionHandler(response: nil, error: StoreError.NetworkError)
      }
    }
  } 
}
</code></pre>

<p>My question is if I can get the same results using generics at a function level instead of class level:</p>

<pre><code>  func performRequest&lt;T: Mappable&gt;(target: Target, completionHandler: (response: T?, error: StoreError?) -&gt; Void) {
    provider.request(target) { result in
      switch result {
      case let .Success(response):
          // blah, blah
      case .Failure(_):
          // bleh, bleh
      }
    }
  } 
</code></pre>

<p>I've tried it and I get a build error on my code:</p>

<p><code>Generic parameter "T" could not be inferred</code></p>