How to get the right selector from URLSession.dataTask(with:completionHandler:) on Xcode 11.5?

那年仲夏 提交于 2021-01-29 10:01:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!