<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionTaskDelegate/urlSession(_:task:didCompleteWithError:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLSessionTaskDelegate(im)URLSession:task:didCompleteWithError:"
  },
  "title" : "urlSession(_:task:didCompleteWithError:)"
}
-->

# urlSession(_:task:didCompleteWithError:)

Tells the delegate that the task finished transferring data.

```
optional func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: (any Error)?)
```

## Parameters

`session`

The session containing the task that has finished transferring data.

`task`

The task that has finished transferring data.

`error`

If an error occurred, an error object indicating how the transfer failed, otherwise `NULL`.

## Discussion

The only errors your delegate receives through the `error` parameter are client-side errors, such as being unable to resolve the hostname or connect to the host. To check for server-side errors, inspect the [`response`](/documentation/Foundation/URLSessionTask/response) property of the `task` parameter received by this callback.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)