选择器dataTask的含糊使用(带有:completionHandler :) [英] ambiguous use of selector dataTask(with: completionHandler:)
问题描述
我正在尝试获取 dataTask(with:completionHandler:)
的selector
在URLSession
中定义的方法,该方法使用如下的URLRequest
对象,但是由于两个方法的参数名称略有不同(两种方法都被重载,方法会出错)(重载的方法-1.一个使用URLRequest对象作为参数,另一个使用URL) :
I'm trying to get a selector
of the dataTask(with:completionHandler:)
method defined in URLSession
which uses URLRequest
object like below, but getting error as there are two methods with slightly two different params names (overloaded methods - 1. one uses URLRequest object as param and another uses URL) :
let dataTaskSelector = #selector(URLSession.dataTask(with: completionHandler:))
I have tried a different approach like below (mentioned in https://github.com/apple/swift-evolution/blob/master/proposals/0022-objc-selectors.md ) but it's also giving same error :
let mySelector = #selector((URLSession.dataTask(with: completionHandler:)) as (URLSession) -> (URLRequest, (Data?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDataTask)
不幸的是,我正在使用最新的Xcode和swift3.到目前为止,我还没有找到具有类似示例的优秀文档.请帮忙.
I'm using latest Xcode and swift 3. I didn't find good documentation with similar example on this unfortunately so far. Please help.
提前谢谢!
推荐答案
您可以这样写selector
.
let selector = #selector((URLSession.dataTask(with:completionHandler:)) as (URLSession) -> (URLRequest, @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask)
该#selector
教程帮助我获得了解决方案.
This #selector
tutorial help me to get the solution.
这篇关于选择器dataTask的含糊使用(带有:completionHandler :)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!