在研究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:)'错误的更多相关文章

  1. Unity报错 : BCE0004: Ambiguous reference 'preview': CameraMotionBlurEditor.preview, UnityEditor.Editor.preview.

    建立项目版本为Unity4.6,改为5.3.4版本,运行项目报如下错误: “BCE0004: Ambiguous reference 'preview': CameraMotionBlurEditor ...

  2. 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 ...

  3. 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 ...

  4. 问题:Custom tool error: Failed to generate code for the service reference 'AppVot;结果:添加Service Reference, 无法为服务生成代码错误的解决办法

    添加Service Reference, 无法为服务生成代码错误的解决办法 我的解决方案是Silverlight+WCF的应用,Done Cretiria定义了需要在做完Service端的代码后首先运 ...

  5. 举例android项目中的string.xml出现这个The character reference must end with the ';' delimiter.错误提示的原因及解决办法

    今天在一个android项目中的string.xml中写这样一个字符串时出现了下面这个错误提示: The reference to entity "说明" must end wit ...

  6. Qt错误:类中使用Q_OBJECT宏导致undefined reference to vtable for "xxx::xxx"错误的原因和解决方法

    在进行Qt编程的时候,有时候会将类的定义和实现都写在源文件中,如果同时在该类中使用信号/槽,那么可能就会遇到 undefined reference to vtable for "xxx:: ...

  7. SWift中 '?' must be followed by a call, member lookup, or subscript 错误解决方案

    那是因为你在使用自己写的分类时没有指定返回的数据类型  指定下返回数据类型就好了 我是用的oc写的分类在Swift中使用的 错误代码 private lazy var btn = UIButton.C ...

  8. C++(2):错误:undefined reference to `__gxx_personality_v0'

    1. Linux Develop Notes     * 编译 c++ 程序需要添加 -lstdc++   sample: gcc -lstdc++ -o test test.c,否则会报 " ...

  9. 错误:undefined reference to `__gxx_personality_v0'

    使用gcc编译C代码,引用了C++ 库,出现这个错误,网上搜到这哥们的文章,解决问题 转自:错误:undefined reference to `__gxx_personality_v0' 1. Li ...

随机推荐

  1. 限制可编辑div只能输入纯文本

    本博客转载自张鑫旭大神的一篇文章:小tip: 如何让contenteditable元素只能输入纯文本,原文地址:http://www.zhangxinxu.com/wordpress/2016/01/ ...

  2. Linux系统——ssh-key连接原理

    SSH是一种客户端连接,在Linux服务器下通过远程的方式将本地电脑连接到对方的电脑上. 远程连接的方式: (1)telnet命令(为明文传输,不安全) (2)(2)SSH(加密传输,安全) 操作的两 ...

  3. cocos代码研究(12)UI之Widget学习笔记

    理论基础 Widget类,所有UI控件的基类. 这类继承自ProtectedNode和LayoutParameterProtocol. 如果你想实现自己的UI控件,你应该继承这个类. 被 VideoP ...

  4. 2016-2017 ACM-ICPC CHINA-Final Solution

    Problem A. Number Theory Problem Solved. 水. #include<bits/stdc++.h> using namespace std; ; typ ...

  5. poj1981 Circle and Points

    地址:http://poj.org/problem?id=1981 题目: Circle and Points Time Limit: 5000MS   Memory Limit: 30000K To ...

  6. zw版【转发·台湾nvp系列Delphi例程】HALCON union1

    zw版[转发·台湾nvp系列Delphi例程]HALCON union1 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, ...

  7. 微信小程序中公用内容

    微信小程序中各个页面调用公用的js 在util.js文件中 // 跳转哪里 function go(where) { wx.reLaunch({ url: where, }) } // 将方法暴露出去 ...

  8. AI学习资料

    OpenAI Gym介绍 http://m.blog.csdn.net/u010510350/article/details/71450232

  9. Fiddler 手机无法上网问题

    一.Fiddler版本升级后需要升级netframework 二.每一个域名点击需要授权 出现此页面依次点击显示详细信息和访问此网站. 有时候网站白板,可能是cdn域名没有授权的原因,可以直接在url ...

  10. 常用php操作redis命令整理(二)哈希类型

    HSET将哈希表key中的域field的值设为value;如果field是哈希表中的一个新建域,并且值设置成功,返回1;如果哈希表中域field已经存在且旧值已被新值覆盖,返回0. <?php ...