3

I use AFNetworking and Mantle library on my project. I decided to migrate swift 3. And I got this error -> "generic parameter 'ResponseType' could not be inferred" on getSources function

ApiBaseHelper.swift

class func GET<ResponseType>(url: String, parameters: AnyObject!, path: String!, callback: @escaping (_ operation: AFHTTPRequestOperation?, _ result: [ResponseType]?, _ error: Error?) -> ()) -> AFHTTPRequestOperation! where ResponseType: MTLJSONSerializing, ResponseType: MTLModel{

    return NetworkManager.sharedInstance!.get(url, parameters: parameters,
        success: {(operation: AFHTTPRequestOperation?, result: Any?) -> Void in
            self.parseResponse(response: result as AnyObject!, operation: operation, path: path, callback: callback)
        },
        failure: { (operation: AFHTTPRequestOperation?, error: Error?) -> Void in
            print("error get request => \(error)")
            callback(operation, nil, error as Error?)
        }
    )
}

ApiHelper.swift

class func getSources(_ callback: @escaping (_ operation: AFHTTPRequestOperation?, _ contents: [Source]?, _ error: Error?) -> ()) {
    var params = [String: AnyObject]()
    params["apiKey"] = API_KEY as AnyObject?
    let url = String(format: SOURCE_PATH)
//generic parameter 'ResponseType' could not be inferred
    GET(url: url, parameters: params as AnyObject!, path: "sources") { (operation: AFHTTPRequestOperation!, result: [Source]?, error: Error!) -> () in
        callback(operation, result, error)
    }
}

1 Answers1

0

Try to change params type to [String: Any]

user3237732
  • 1,976
  • 2
  • 21
  • 28