Xcode8 beta 6 - URLSession with completionHandler

2019-07-12 02:31发布

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条回答
Melony?
2楼-- · 2019-07-12 02:52

I found out that I was calling handleTaskResult which had error as NSError?, but error is now Error?, after changing this, it compiles!

查看更多
登录 后发表回答