问题
On Xcode 11.5 (Swift 5.2.4) the compiler gets confused and shows the error below:
Cannot convert value of type '(URLSession) -> (URL, @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask' to type '(URLSession) -> (URLRequest, @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask' in coercion
I'm trying to get the selector like follows, but the compiler still tries to convert to the version with URL instead:
let selector = #selector(URLSession.dataTask(with:completionHandler:) as (URLSession) -> (URLRequest, @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask)
Update:
I installed Xcode 11.6 (11E708), reinstalled Xcode Command Line Tools, upgraded the project settings, cleared all derived data, but I'm still getting the same error.
来源:https://stackoverflow.com/questions/63608385/how-to-get-the-right-selector-from-urlsession-datataskwithcompletionhandler