title: Generic function to map JSON objects with ObjectMapper
body: <p>I have a generic function: </p>
  
  <pre><code>   func toObjectMapper&lt;T: Mappable&gt;(mapper: T, success: (result: Mappable) -&gt; Void, failure: (error: NSError) -&gt; Void){
          let alomofireApiRequest = AlamofireApiRequest(apiRequest: self)
          Alamofire.request(alomofireApiRequest)
              .responseObject { (response: Response&lt;T, NSError&gt;) in
                  guard let value = response.result.value else {
                      failure(error: response.result.error!)
                      return
                  }
                  success(result: value)
          }
  
      }
  </code></pre>
  
  <p>And I want to call it like this: </p>
  
  <pre><code>public func login(login: String, password: String) -&gt; UserResponse {
          let params = ["email":login, "password":password]
  
          let request = ApiRequest(method: .POST, path: "login", parameters: params)
  
          request.toObjectMapper(UserResponse.self, success: { result in
                  print(result)
  
              }, failure: { error in
                  print(error.description)
          })
      }
  </code></pre>
  
  <p>But I always get this error:</p>
  
  <pre><code> Cannot invoke 'toObjectMapper' with an argument list of type '(UserResponse.Type, success: (result: Mappable) -&gt; Void, failure: (error: NSError) -&gt; Void)'
  </code></pre>
  
  <p>This is my userResponse:</p>
  
  <pre><code>import Foundation
  import ObjectMapper
  import RealmSwift
  
  public class  UserResponse: Object, Mappable {
      dynamic var id = 0
      dynamic var name = ""
      dynamic var address = ""
      dynamic var zipcode = ""
      dynamic var city = ""
      dynamic var country = ""
      dynamic var vat = ""
      dynamic var email = ""
      dynamic var created_at = NSDate()
      dynamic var updated_at = NSDate()
  
      override public static func primaryKey() -&gt; String? {
          return "id"
      }
  
      //Impl. of Mappable protocol
      required convenience public init?(_ map: Map) {
          self.init()
      }
  
      public func mapping(map: Map) {
          id    &lt;- map["id"]
          name &lt;- map["name"]
          address &lt;- map["address"]
          zipcode &lt;- map["zipcode"]
          city &lt;- map["city"]
          country &lt;- map["country"]
          vat &lt;- map["vat"]
          email &lt;- map["email"]
          created_at &lt;- map["created_at"]
          updated_at &lt;- map["updated_at"]
  
  
      }
  }
  </code></pre>
  
  <p>Any help ?</p>