问题描述
从beta 5到beta 6更改后,我似乎根本无法在代码中使用此方法.
open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDataTask
我的代码:
let task = self.createSession().dataTask(with: request, completionHandler: { (data, response, error) in
self.handleTaskResult(data: data, response: response, error: error, completionHandler: completionHandlerIncoming)
})
我知道了"Cannot invoke 'dataTask' with an argument list of type '(with: URLRequest, completionHandler: (Data?, URLResponse?, Error?) -> Void)'"
.即使这是xcode给我的功能的完成.
如果我再尝试:
let task = self.createSession().dataTask(with: request) { data, response, error in
self.handleTaskResult(data: data, response: response, error: error, completionHandler: completionHandlerIncoming)
}
它仍然不起作用.
更新:
我发现我正在调用handleTaskResult,它的错误为NSError?
,但现在错误为Error?
,更改此错误后,它将编译!
我发现我正在调用handleTaskResult,它的错误为NSError?
,但现在错误为Error?
,更改此错误后,它将编译! >
I can't seem to use this method in my code at all after changing from beta 5 til beta 6.
open func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDataTask
My code:
let task = self.createSession().dataTask(with: request, completionHandler: { (data, response, error) in
self.handleTaskResult(data: data, response: response, error: error, completionHandler: completionHandlerIncoming)
})
I get that "Cannot invoke 'dataTask' with an argument list of type '(with: URLRequest, completionHandler: (Data?, URLResponse?, Error?) -> Void)'"
. Even though this is the completion of the function xcode gives me.
If I then try:
let task = self.createSession().dataTask(with: request) { data, response, error in
self.handleTaskResult(data: data, response: response, error: error, completionHandler: completionHandlerIncoming)
}
It still does not work.
UPDATE:
I found out that I was calling handleTaskResult which had error as NSError?
, but error is now Error?
, after changing this, it compiles!
I found out that I was calling handleTaskResult which had error as NSError?
, but error is now Error?
, after changing this, it compiles!
这篇关于Xcode8 Beta 6-带有完成处理程序参数的URLSession不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!