3

我在我的项目中使用 AFNetworking 和 Mantle 库。我决定迁移 swift 3。我在 getSources 函数上遇到了这个错误->“无法推断通用参数'ResponseType'”

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)
    }
}
4

1 回答 1

0

尝试将参数类型更改为 [String: Any]

于 2016-09-28T20:41:25.033 回答