问题
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)
I'm using latest Xcode and swift 3. I didn't find good documentation with similar example on this unfortunately so far. Please help.
Thanks in advance!
回答1:
You can write that selector
like this way.
let selector = #selector((URLSession.dataTask(with:completionHandler:)) as (URLSession) -> (URLRequest, @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask)
This #selector
tutorial help me to get the solution.
来源:https://stackoverflow.com/questions/41545512/ambiguous-use-of-selector-datataskwith-completionhandler