<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLConnectionDelegate/connection(_:didFailWithError:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLConnectionDelegate(im)connection:didFailWithError:"
  },
  "title" : "connection(_:didFailWithError:)"
}
-->

# connection(_:didFailWithError:)

Sent when a connection fails to load its request successfully.

```
optional func connection(_ connection: NSURLConnection, didFailWithError error: any Error)
```

## Parameters

`connection`

The connection sending the message.

`error`

An error object containing details of why the connection failed to load the request successfully.

## Discussion

Once the delegate receives this message, it will receive no further messages for `connection`.

---

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)