2

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!

Bjarte
  • 2,167
  • 5
  • 27
  • 37
  • I cannot spot an error at first sight. Does it compile with an "empty" completion handler `{ (data, response, error) in }` ? – Martin R Aug 17 '16 at 05:19
  • yes it does compile when empty, so I'm wondering if its anything inside, I will experiment some more. – Bjarte Aug 17 '16 at 05:20
  • Oh I found out what it was! I had a parameter with NSError but now the completionHandler uses Error, how ever I got the error on the other line.... hmmmm... – Bjarte Aug 17 '16 at 05:27

1 Answers1

1

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

Bjarte
  • 2,167
  • 5
  • 27
  • 37