Issue when implementing NSURLSession

I have recently been playing with NSURLSession and seeing the benefits of using this over the old method.

Today I came across a slight issue that is worth noting. During my programming session I was implementing the delegates. I started with NSURLSessionDelegate then moved onto NSURLSessionTaskDelegate. At this point I decided to test the code and found that the following method was called in my delegate object

– (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error

I tried to output the error using

NSLog(@”%@”, [error localizedDescription]);

But unfortunately this was not helpful as I received Null. I originally thought that there was an error in my coding however I could not locate 1. On further checking I found that I have made a couple of assumptions and I believe they were quite well founded.

The description of – URLSession:task:didCompleteWithError: is as follows:

Tells the delegate that the task finished transferring data.

Unfortunately I do not believe the method is named very well. As the description states this method is called when an error occurs. If no errors occur then the task completed successfully.

To ensure that the request was successful something along the lines of the example brow will work.

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
{
    //TODO Implement method
    if (error == Nil) {
        //TODO ascertain the failure and report failure to the caller
        return;
    }
    //TODO Report success
}

Tell us your thoughts