【发布时间】:2016-08-31 16:25:51
【问题描述】:
我有一段我几乎在我的代码中到处使用的普通代码:
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration:configuration)
let listTask = session.dataTask(with: theRequest, completionHandler: {[weak self](data, response, error) in
})
然而在一个特定的类中,编译器抱怨:
不能使用类型为 '( 的参数列表: URLRequest, completionHandler: (Data?, URLResponse?, Error?) -> ())'
需要一个类型为 '(with: URLRequest, completionHandler: > (Data?, URLResponse?, Error?) -> Void)'的参数列表
它如何推断闭包的返回值是 () 而不是预期的 Void?我反复复制其他类的代码,以免写错了。
【问题讨论】:
-
尝试删除
[weak self]
标签: nsurlsession swift3