Xcode8 beta 6 - URLSession with completionHandler argument not working

596 views Asked by At

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

There are 1 answers

0
Bjarte On BEST ANSWER

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