选择器dataTask的含糊使用(带有:completionHandler :) [英] ambiguous use of selector dataTask(with: completionHandler:)

查看:84
本文介绍了选择器dataTask的含糊使用(带有: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆