Ambiguous reference to member 'dataTask(with:completionHandle:)'错误
在研究IOS的网络请求过程中,因为NSURLConnection已经过时,需要引用到URLSession
var url:NSURL=NSURL(string: "http://3g.163.com")!
var request:NSURLRequest=NSURLRequest(url: url as URL)
//创建会话对象
let session=URLSession.shared
let date = Date()
print("创建任务, 时间:\(date.timeIntervalSince1970)")
//初始化请求
let dataTask = session.dataTask(with: request, completionHandler: { (data,resp,err) in
})
编译时候一直报错,Ambiguous reference to member 'dataTask(with:completionHandle:)'错误。
开始我一直怀疑是completionHandle错误,不停的去查资料,后来突然发现,原来错误在with :request
通过定义去查看URLSession
open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDataTask
/////////////////////////////
with request:URLRequest
我上面用NSURLRequest,我真的是醉了,这个错误错的离谱啊。
写在这里估计大家都明白错误原因了。花了一天的时间,希望此文对自己有所提高
Ambiguous reference to member 'dataTask(with:completionHandle:)'错误的更多相关文章
- Unity报错 : BCE0004: Ambiguous reference 'preview': CameraMotionBlurEditor.preview, UnityEditor.Editor.preview.
建立项目版本为Unity4.6,改为5.3.4版本,运行项目报如下错误: “BCE0004: Ambiguous reference 'preview': CameraMotionBlurEditor ...
- ArcEngine :The XY domain on the spatial reference is not set or invalid错误
在创建数据集的时候,提示The XY domain on the spatial reference is not set or invalid错误. 原因:未设置空间参考(ISpatialRefer ...
- ArcEngine:The XY domain on the spatial reference is not set or invalid错误
在创建数据集的时候,提示The XY domain on the spatial reference is not set or invalid错误. 原因:未设置空间参考(ISpatialRefer ...
- 问题:Custom tool error: Failed to generate code for the service reference 'AppVot;结果:添加Service Reference, 无法为服务生成代码错误的解决办法
添加Service Reference, 无法为服务生成代码错误的解决办法 我的解决方案是Silverlight+WCF的应用,Done Cretiria定义了需要在做完Service端的代码后首先运 ...
- 举例android项目中的string.xml出现这个The character reference must end with the ';' delimiter.错误提示的原因及解决办法
今天在一个android项目中的string.xml中写这样一个字符串时出现了下面这个错误提示: The reference to entity "说明" must end wit ...
- Qt错误:类中使用Q_OBJECT宏导致undefined reference to vtable for "xxx::xxx"错误的原因和解决方法
在进行Qt编程的时候,有时候会将类的定义和实现都写在源文件中,如果同时在该类中使用信号/槽,那么可能就会遇到 undefined reference to vtable for "xxx:: ...
- SWift中 '?' must be followed by a call, member lookup, or subscript 错误解决方案
那是因为你在使用自己写的分类时没有指定返回的数据类型 指定下返回数据类型就好了 我是用的oc写的分类在Swift中使用的 错误代码 private lazy var btn = UIButton.C ...
- C++(2):错误:undefined reference to `__gxx_personality_v0'
1. Linux Develop Notes * 编译 c++ 程序需要添加 -lstdc++ sample: gcc -lstdc++ -o test test.c,否则会报 " ...
- 错误:undefined reference to `__gxx_personality_v0'
使用gcc编译C代码,引用了C++ 库,出现这个错误,网上搜到这哥们的文章,解决问题 转自:错误:undefined reference to `__gxx_personality_v0' 1. Li ...
随机推荐
- Qt emit的使用
1. 假设现在我定义了一个类A,现在想在A的一个函数void A::function1()当中的结尾处emit一个信号signal1(),然后利用这个信号触发另一个类B进行某项操作void B::fu ...
- Xcel 测试版使用手册
基于无任何文笔可言,所以直接上使用方法吧. 1.引用dll,如何引用dll请谷歌. 2.使用 //实例化对象 LT.XMLExcel.XlsxOption xOption = new LT.XMLEx ...
- 2018-2019 ICPC, NEERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred) Solution
A. Alice the Fan Solved. 题意: 两个人打网球,要求teamA 的得分与其他队伍拉开尽量大 输出合法的方案 思路: $dp[i][j][k][l] 表示 A 赢i局,其他队伍赢 ...
- 20155331 2016-2017-2 《Java程序设计》第8周学习总结
20155331 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 NIO与NIO2 NIO使用频道(channel)来衔接数据节点,对数据区的标记提供了cle ...
- python 封装时间常用操作方法-time,datetime
封装脚本: #encoding=utf-8import timefrom datetime import timedelta,date def date_time_chinese(): prin ...
- 【运维技术】VM虚拟机上使用centos7安装docker启动gogs服务教程【含B站视频教程】
VM虚拟机上使用centos7安装docker启动gogs服务视频教程 BiliBili视频教程链接飞机票,点我 使用VMware Workstation安装Centos7 MinMal系统 第一步: ...
- logstash收集Nginx日志,转换为JSON格式
Nginx日志处理为JSON格式,并放置在http区块: log_format json '{"@timestamp":"$time_iso8601",' '& ...
- [SpringBoot] - 配置文件的多种形式及优先级
学习两个注解: @PropertySource @ImportResource ↓ @ConfigurationProperties 与 @Bean 结合为属性赋值 与 ...
- 使用ntpdate工具校正linux服务器时间
当Linux服务器的时间不对的时候,可以使用ntpdate工具来校正时间. 安装:yum install ntpdate ntpdate简单用法: # ntpdate ip # ntpdate 210 ...
- package 'yaml-cpp' not found
-- Using these message generators: gencpp;genlisp;genpy -- checking for module 'yaml-cpp' -- package ...