Swift Argument标签'(_:,destination:)'不匹配任何可用的重载

时间:2018-05-14 16:47:33

标签: swift

我将项目转换为Swift 4.1并在尝试重制时出错

 private func download(downloadable: Downloadable, destination: Request.DownloadFileDestination) -> Request {
        var downloadTask: URLSessionDownloadTask!
        switch downloadable {
        case .Request(let request):
            dispatch_sync(queue) {
                downloadTask = self.session.downloadTaskWithRequest(request)
            }
        case .ResumeData(let resumeData):
            dispatch_sync(queue) {
                downloadTask = self.session.downloadTaskWithResumeData(resumeData)
            }
        }
        let request = Request(session: session, task: downloadTask)
        if let downloadDelegate = request.delegate as? Request.DownloadTaskDelegate {
            downloadDelegate.downloadTaskDidFinishDownloadingToURL = { session, downloadTask, URL in
                return destination(URL, downloadTask.response as! NSHTTPURLResponse)
            }
        }
        delegate[request.delegate.task] = request.delegate
        if startRequestsImmediately {
            request.resume()
        }
        return request
    }

public func download(
    method: Method,
    _ URLString: URLStringConvertible,
    parameters: [String: AnyObject]? = nil,
    encoding: ParameterEncoding = .URL,
    headers: [String: String]? = nil,
    destination: Request.DownloadFileDestination)
    -> Request
{
    let mutableURLRequest = URLRequest(method: method, URLString, headers: headers)
    let encodedURLRequest = encoding.encode(URLRequest: mutableURLRequest, parameters: parameters).0
    return download(encodedURLRequest, destination: destination)
}

当我打电话

错误:

  

参数标签'(_:,destination :)'不匹配任何可用的重载

1 个答案:

答案 0 :(得分:0)

download函数都没有在错误中显示该签名。

您可以将第一个download称为:

let result = download(downloadable: someValue, destination: someOtherValue)

或者您将第二个download称为:

let result = download(method: someMethod, someURLString, destination: someDestination)

当然,第二次调用也可以有一个或多个可选参数。

很可能你想改变:

return download(encodedURLRequest, destination: destination)

为:

return download(downloadable: encodedURLRequest, destination: destination)

这假设encodedURLRequest的类型为Downloadable