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 ...
随机推荐
- 安装memcached扩展 验证过了可行
. 安装libmemached 复制代码 代码如下: wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached ...
- 一次org.springframework.jdbc.BadSqlGrammarException ### Error querying database Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException问题排查过程
先说结论: 因为在表设计中有一个商品描述字段被设置为desc,但desc是mysql中的关键字,如select id,name,desc,price from product;这条sql语句在查询时的 ...
- spring AOP的注解实例
上一篇写了spring AOP 的两种代理,这里开始AOP的实现了,个人喜欢用注解方式,原因是相对于XML方式注解方式更灵活,更强大,更可扩展.所以XML方式的AOP实现就被我抛弃了. 实现Sprin ...
- StarUML激活
感谢 http://blog.csdn.net/mergades/article/details/46662413 1,打开对应 mac版本的安装包位置,在对应目录/Applications/Sta ...
- BootStrap一页通(样式+组件+插件)
bootstrap是一种前端框架,实现美观的页面效果.使用BootStrap的前期工作(注意顺序): <!DOCTYPT html>:因为Bootstrap用到了h5的特性,所以需要此步. ...
- P1131 [ZJOI2007]时态同步(树形dp)
P1131 [ZJOI2007]时态同步 设$f[i]$为与$i$与最远的点的距离 在dfs时每次更新的时候顺便统计一下长度,不同的话就改成最长的那条并更新答案 #include<iostrea ...
- .net Core 发布并布署到Iis
配置 Program.cs代码 namespace WebApplication8 { public class Program { public static void Mai ...
- Android 开机Process xxx (pid xxxx) has died问题分析
系统中有一个监听BOOT_COMPLETED广播的自启应用,概率性出现启动后被kill掉的现象.Log如下: - :: I ActivityManager: Process com.test.xxx ...
- InstallShield 2015 LimitedEdition VS2012 运行bat文件
转载:http://www.cnblogs.com/fengwenit/p/4271150.html 运行bat文件 网上很多介绍如何运行bat的方法,但我这个是limted 版本,不适用. 1. ...
- pairs 和 ipairs异同
同:都是能遍历集合(表.数组) 异:ipairs 仅仅遍历值,按照索引升序遍历,索引中断停止遍历.即不能返回 nil,只能返回数字 0,如果遇到 nil 则退出.它只能遍历到集合中出现的第一个不是整数 ...