问题
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!
回答1:
I found out that I was calling handleTaskResult which had error as NSError?
, but error is now Error?
, after changing this, it compiles!
来源:https://stackoverflow.com/questions/38988474/xcode8-beta-6-urlsession-with-completionhandler-argument-not-working