Xcode8 beta 6 - URLSession with completionHandler argument not working

百般思念 提交于 2019-12-24 00:48:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!